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.tctest;
005:
006: import com.tc.object.config.ConfigVisitor;
007: import com.tc.object.config.DSOClientConfigHelper;
008: import com.tc.object.config.TransparencyClassSpec;
009: import com.tc.simulator.app.ApplicationConfig;
010: import com.tc.simulator.listener.ListenerProvider;
011: import com.tctest.runner.AbstractTransparentApp;
012:
013: import java.util.ArrayList;
014: import java.util.List;
015:
016: public class ByteCodePerformanceTestApp extends AbstractTransparentApp {
017:
018: private List instrumentedObjects = new ArrayList();
019: private List instrumentedUnSharedObjects = new ArrayList();
020: // private List uninstrumentedObjects = new ArrayList();
021:
022: private final static int COUNT = 50;
023:
024: public ByteCodePerformanceTestApp(String appId,
025: ApplicationConfig cfg, ListenerProvider listenerProvider) {
026: super (appId, cfg, listenerProvider);
027: }
028:
029: public void run() {
030: new InstrumentedObject(true);
031: long start = System.currentTimeMillis();
032: long s2 = 0;
033: if (true) {
034: synchronized (this .instrumentedObjects) {
035: s2 = System.currentTimeMillis();
036: for (int i = 0; i < COUNT; i++) {
037: instrumentedObjects
038: .add(new InstrumentedObject(true));
039: }
040: System.out.println("CREATED INSTRUMENTED -INNER:"
041: + (System.currentTimeMillis() - s2));
042: }
043:
044: System.out.println("CREATED INSTRUMENTED:"
045: + (System.currentTimeMillis() - start));
046:
047: start = System.currentTimeMillis();
048: System.gc();
049: synchronized (this .instrumentedObjects) {
050: System.out.println("QUERY INSTRUMENTED START:"
051: + (System.currentTimeMillis() - start));
052: for (int j = 0; j < 500; j++) {
053: for (int i = 0; i < COUNT; i++) {
054: InstrumentedObject o = (InstrumentedObject) instrumentedObjects
055: .get(i);
056: o.accessValues();
057: }
058: }
059: }
060: System.out.println("QUERY INSTRUMENTED:"
061: + (System.currentTimeMillis() - start));
062: } else {
063: // start = System.currentTimeMillis();
064: // synchronized (this.instrumentedObjects) {
065: // for (int i = 0; i < COUNT; i++) {
066: // InstrumentedObject o = (InstrumentedObject) instrumentedObjects.get(i);
067: // o.setValues();
068: // }
069: // }
070: // System.out.println("SET INSTRUMENTED:" + (System.currentTimeMillis() - start));
071: //
072: start = System.currentTimeMillis();
073: for (int i = 0; i < COUNT; i++) {
074: instrumentedUnSharedObjects.add(new InstrumentedObject(
075: true));
076: }
077: System.out.println("CREATED INSTRUMENTED UNSHARED:"
078: + (System.currentTimeMillis() - start));
079: System.gc();
080: start = System.currentTimeMillis();
081: for (int j = 0; j < 500; j++) {
082: for (int i = 0; i < COUNT; i++) {
083: InstrumentedObject o = (InstrumentedObject) instrumentedUnSharedObjects
084: .get(i);
085: o.accessValues();
086: }
087: }
088: System.out.println("QUERY INSTRUMENTED UNSHARED:"
089: + (System.currentTimeMillis() - start));
090: }
091: //
092: // start = System.currentTimeMillis();
093: // for (int j = 0; j < 500; j++) {
094: // for (int i = 0; i < COUNT; i++) {
095: // InstrumentedObject o = (InstrumentedObject) instrumentedUnSharedObjects.get(i);
096: // o.setValues();
097: // }
098: // }
099: // System.out.println("SET INSTRUMENTED UNSHARED:" + (System.currentTimeMillis() - start));
100: //
101: // start = System.currentTimeMillis();
102: // for (int i = 0; i < COUNT; i++) {
103: // uninstrumentedObjects.add(new UnInstrumentedObject(true));
104: // }
105: // System.out.println("CREATED UNINSTRUMENTED:" + (System.currentTimeMillis() - start));
106: //
107: // start = System.currentTimeMillis();
108: // for (int j = 0; j < 500; j++) {
109: // for (int i = 0; i < COUNT; i++) {
110: // UnInstrumentedObject o = (UnInstrumentedObject) uninstrumentedObjects.get(i);
111: // o.accessValues();
112: // }
113: // }
114: // System.out.println("QUERY UNINSTRUMENTED:" + (System.currentTimeMillis() - start));
115: //
116: // start = System.currentTimeMillis();
117: // for (int j = 0; j < 500; j++) {
118: // for (int i = 0; i < COUNT; i++) {
119: // UnInstrumentedObject o = (UnInstrumentedObject) uninstrumentedObjects.get(i);
120: // o.setValues();
121: // }
122: // }
123: // System.out.println("SET UNINSTRUMENTED:" + (System.currentTimeMillis() - start));
124:
125: }
126:
127: public List test() {
128: if (System.currentTimeMillis() == 100) {
129: synchronized (this ) {
130:
131: boolean steve = true;
132: System.out.println(steve);
133: return instrumentedObjects;
134: }
135: }
136: return instrumentedObjects;
137:
138: }
139:
140: public static void visitL1DSOConfig(ConfigVisitor visitor,
141: DSOClientConfigHelper config) {
142: String testClass = InstrumentedObject.class.getName();
143: config.getOrCreateSpec(testClass);
144: testClass = ByteCodePerformanceTestApp.class.getName();
145: String methodExpression = "* " + testClass + ".*(..)";
146: config.addWriteAutolock(methodExpression);
147: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
148: spec.addRoot("instrumentedObjects", "instrumentedObjects");
149: }
150: }
|