001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.config;
005:
006: import com.tc.object.bytecode.ByteCodeUtil;
007:
008: import java.util.HashSet;
009: import java.util.Hashtable;
010: import java.util.Set;
011:
012: public class TransparencyCodeSpecImpl implements TransparencyCodeSpec {
013: private final static Set MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS = new HashSet();
014:
015: private boolean arrayOperatorInstrumentationReq;
016: private boolean arraycopyInstrumentationReq;
017: private boolean fieldInstrumentationReq;
018: private boolean waitNotifyInstrumentationReq;
019: private boolean monitorInstrumentationReq;
020:
021: static {
022: MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS.add(Hashtable.class
023: .getName());
024: }
025:
026: public static TransparencyCodeSpec getDefaultPhysicalCodeSpec() {
027: TransparencyCodeSpec defaultPhysicalCodeSpec = new TransparencyCodeSpecImpl();
028: defaultPhysicalCodeSpec
029: .setArrayOperatorInstrumentationReq(true);
030: defaultPhysicalCodeSpec.setArraycopyInstrumentationReq(true);
031: defaultPhysicalCodeSpec.setFieldInstrumentationReq(true);
032: defaultPhysicalCodeSpec.setWaitNotifyInstrumentationReq(true);
033: defaultPhysicalCodeSpec.setMonitorInstrumentationReq(true);
034: return defaultPhysicalCodeSpec;
035: }
036:
037: public static TransparencyCodeSpec getDefaultLogicalCodeSpec() {
038: TransparencyCodeSpec defaultSpec = new TransparencyCodeSpecImpl();
039: return defaultSpec;
040: }
041:
042: public static TransparencyCodeSpec getDefaultCodeSpec(
043: String className, boolean isLogical, boolean isAutolock) {
044: if (isLogical) {
045: TransparencyCodeSpec codeSpec = getDefaultLogicalCodeSpec();
046: if (MONITOR_INSTRUMENTATION_REQ_LOGICAL_CLASS
047: .contains(className)) {
048: codeSpec.setMonitorInstrumentationReq(isAutolock);
049: }
050: return codeSpec;
051: }
052: return getDefaultPhysicalCodeSpec();
053: }
054:
055: public TransparencyCodeSpecImpl() {
056: super ();
057: }
058:
059: public boolean isArraycopyInstrumentationReq(String className,
060: String methodName) {
061: return arraycopyInstrumentationReq
062: && "java/lang/System".equals(className)
063: && "arraycopy".equals(methodName);
064: }
065:
066: public void setArraycopyInstrumentationReq(
067: boolean arraycopyInstrumentationReq) {
068: this .arraycopyInstrumentationReq = arraycopyInstrumentationReq;
069: }
070:
071: public boolean isArrayOperatorInstrumentationReq() {
072: return arrayOperatorInstrumentationReq;
073: }
074:
075: public void setArrayOperatorInstrumentationReq(
076: boolean arrayOperatorInstrumentationReq) {
077: this .arrayOperatorInstrumentationReq = arrayOperatorInstrumentationReq;
078: }
079:
080: public boolean isFieldInstrumentationReq(String fieldName) {
081: // For jdk compiler, the <init> method of an anonymous inner class contains
082: // code to set the synthetic fields, followed by the super() call. This creates
083: // problem if we try to use TC setter method for the synthetic fields before
084: // the super() method. So, before the super() call, we will not instrument
085: // to use the TC setter method.
086: return fieldInstrumentationReq
087: && !ByteCodeUtil.isTCSynthetic(fieldName);
088: }
089:
090: public void setFieldInstrumentationReq(
091: boolean fieldInstrumentationReq) {
092: this .fieldInstrumentationReq = fieldInstrumentationReq;
093: }
094:
095: public boolean isWaitNotifyInstrumentationReq() {
096: return waitNotifyInstrumentationReq;
097: }
098:
099: public void setWaitNotifyInstrumentationReq(
100: boolean waitNotifyInstrumentationReq) {
101: this .waitNotifyInstrumentationReq = waitNotifyInstrumentationReq;
102: }
103:
104: public boolean isMonitorInstrumentationReq() {
105: return monitorInstrumentationReq;
106: }
107:
108: public void setMonitorInstrumentationReq(
109: boolean monitorInstrumentationReq) {
110: this.monitorInstrumentationReq = monitorInstrumentationReq;
111: }
112:
113: }
|