KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > TransparencyCodeSpec


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config;
5
6 import com.tc.object.bytecode.ByteCodeUtil;
7
8 import java.util.HashSet JavaDoc;
9 import java.util.Hashtable JavaDoc;
10 import java.util.Set JavaDoc;
11
12 public class TransparencyCodeSpec {
13   private final static Set JavaDoc MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS = new HashSet JavaDoc();
14   
15   private boolean arrayOperatorInstrumentationReq;
16   private boolean arraycopyInstrumentationReq;
17   private boolean fieldInstrumentationReq;
18   private boolean waitNotifyInstrumentationReq;
19   private boolean monitorInstrumentationReq;
20   
21   static {
22     MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS.add(Hashtable JavaDoc.class.getName());
23   }
24
25   public static TransparencyCodeSpec getDefaultPhysicalCodeSpec() {
26     TransparencyCodeSpec defaultPhysicalCodeSpec = new TransparencyCodeSpec();
27     defaultPhysicalCodeSpec.setArrayOperatorInstrumentationReq(true);
28     defaultPhysicalCodeSpec.setArraycopyInstrumentationReq(true);
29     defaultPhysicalCodeSpec.setFieldInstrumentationReq(true);
30     defaultPhysicalCodeSpec.setWaitNotifyInstrumentationReq(true);
31     defaultPhysicalCodeSpec.setMonitorInstrumentationReq(true);
32     return defaultPhysicalCodeSpec;
33   }
34
35   public static TransparencyCodeSpec getDefaultLogicalCodeSpec() {
36     TransparencyCodeSpec defaultSpec = new TransparencyCodeSpec();
37     return defaultSpec;
38   }
39
40   public static TransparencyCodeSpec getDefaultCodeSpec(String JavaDoc className, boolean isLogical, boolean isAutolock) {
41     if (isLogical) {
42       TransparencyCodeSpec codeSpec = getDefaultLogicalCodeSpec();
43       if (MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS.contains(className)) {
44         codeSpec.setMonitorInstrumentationReq(isAutolock);
45       }
46       return codeSpec;
47     }
48     return getDefaultPhysicalCodeSpec();
49   }
50
51   public TransparencyCodeSpec() {
52     super();
53   }
54
55   public boolean isArraycopyInstrumentationReq(String JavaDoc className, String JavaDoc methodName) {
56     return arraycopyInstrumentationReq && "java/lang/System".equals(className) && "arraycopy".equals(methodName);
57   }
58
59   public void setArraycopyInstrumentationReq(boolean arraycopyInstrumentationReq) {
60     this.arraycopyInstrumentationReq = arraycopyInstrumentationReq;
61   }
62
63   public boolean isArrayOperatorInstrumentationReq() {
64     return arrayOperatorInstrumentationReq;
65   }
66
67   public void setArrayOperatorInstrumentationReq(boolean arrayOperatorInstrumentationReq) {
68     this.arrayOperatorInstrumentationReq = arrayOperatorInstrumentationReq;
69   }
70
71   public boolean isFieldInstrumentationReq(String JavaDoc fieldName) {
72     // For jdk compiler, the <init> method of an anonymous inner class contains
73
// code to set the synthetic fields, followed by the super() call. This creates
74
// problem if we try to use TC setter method for the synthetic fields before
75
// the super() method. So, before the super() call, we will not instrument
76
// to use the TC setter method.
77
return fieldInstrumentationReq && !ByteCodeUtil.isTCSynthetic(fieldName);
78   }
79
80   public void setFieldInstrumentationReq(boolean fieldInstrumentationReq) {
81     this.fieldInstrumentationReq = fieldInstrumentationReq;
82   }
83
84   public boolean isWaitNotifyInstrumentationReq() {
85     return waitNotifyInstrumentationReq;
86   }
87
88   public void setWaitNotifyInstrumentationReq(boolean waitNotifyInstrumentationReq) {
89     this.waitNotifyInstrumentationReq = waitNotifyInstrumentationReq;
90   }
91
92   public boolean isMonitorInstrumentationReq() {
93     return monitorInstrumentationReq;
94   }
95
96   public void setMonitorInstrumentationReq(boolean monitorInstrumentationReq) {
97     this.monitorInstrumentationReq = monitorInstrumentationReq;
98   }
99
100 }
101
Popular Tags