Source Code Cross Referenced for JoinPointCostsMeasurement.java in  » Byte-Code » PROSE » measurements » suites » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » PROSE » measurements.suites 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Id$
002:        //=====================================================================
003:        //
004:        //(history at end)
005:        //
006:
007:        package measurements.suites;
008:
009:        import java.lang.reflect.Field;
010:        import java.lang.reflect.Method;
011:
012:        import junit.framework.Test;
013:        import ch.ethz.inf.util.junit.PerformanceTest;
014:        import ch.ethz.inf.util.junit.PerformanceTestSuite;
015:        import ch.ethz.jvmai.*;
016:
017:        /**
018:         * Measure the join point costs.
019:         * 
020:         * @version $Revision$
021:         * @author Johann Gyger
022:         */
023:        public class JoinPointCostsMeasurement extends PerformanceTest {
024:
025:            public static final boolean CHECK_ASSERT = false;
026:
027:            public static final boolean USE_PROSE = false;
028:
029:            public static int fieldAccessCount;
030:            public static int fieldModificationCount;
031:            public static int methodEntryCount;
032:            public static int methodExitCount;
033:            public static int exceptionThrowCount;
034:            public static int exceptionCatchCount;
035:
036:            public static Test suite() {
037:                return new PerformanceTestSuite(JoinPointCostsMeasurement.class);
038:            }
039:
040:            protected TestHook hook;
041:
042:            protected JVMAspectInterface aspectInterface;
043:
044:            protected MyTestClass testObject = new MyTestClass();
045:
046:            protected Method methodEntry;
047:
048:            protected Method methodExit;
049:
050:            protected Field field;
051:
052:            public JoinPointCostsMeasurement(String name) {
053:                super (name);
054:                RANGE = new int[] { 10000000 };
055:            }
056:
057:            protected void setUp() throws Exception {
058:                if (USE_PROSE) {
059:                    String providerName = System
060:                            .getProperty("ch.ethz.prose.JVMAIProvider");
061:                    Class providerClass = Class.forName(providerName);
062:                    Provider provider = (Provider) providerClass.newInstance();
063:
064:                    aspectInterface = provider.getAspectInterface();
065:                    aspectInterface.startup(null, true);
066:
067:                    hook = new TestHook();
068:                    aspectInterface.setJoinPointHook(hook);
069:
070:                    methodEntry = MyTestClass.class.getDeclaredMethod(
071:                            "myMethodEntry", new Class[] {});
072:                    methodExit = MyTestClass.class.getDeclaredMethod(
073:                            "myMethodExit", new Class[] {});
074:                    field = MyTestClass.class.getDeclaredField("myField");
075:                }
076:
077:                fieldAccessCount = 0;
078:                fieldModificationCount = 0;
079:                methodEntryCount = 0;
080:                methodExitCount = 0;
081:                exceptionThrowCount = 0;
082:                exceptionCatchCount = 0;
083:            }
084:
085:            protected void tearDown() {
086:                if (USE_PROSE)
087:                    aspectInterface.teardown();
088:            }
089:
090:            public void testMethod0() {
091:                testObject.myMethod(RUNS);
092:            }
093:
094:            public void testMethodEntry() {
095:                if (USE_PROSE) {
096:                    aspectInterface.setMethodEntryWatch(methodEntry,
097:                            new Object());
098:                    aspectInterface.resumeNotification(Thread.currentThread());
099:                }
100:
101:                testObject.myMethodEntry(RUNS);
102:
103:                if (CHECK_ASSERT)
104:                    assertEquals("Hook notifications", RUNS, methodEntryCount);
105:            }
106:
107:            public void testMethodExit() {
108:                if (USE_PROSE) {
109:                    aspectInterface
110:                            .setMethodExitWatch(methodExit, new Object());
111:                    aspectInterface.resumeNotification(Thread.currentThread());
112:                }
113:
114:                testObject.myMethodExit(RUNS);
115:
116:                if (CHECK_ASSERT)
117:                    assertEquals("Hook notifications", RUNS, methodExitCount);
118:            }
119:
120:            public void testFieldAccess0() {
121:                testObject.myFieldAccess(RUNS);
122:            }
123:
124:            public void testFieldAccess() {
125:                if (USE_PROSE) {
126:                    aspectInterface.setFieldAccessWatch(field, new Object());
127:                    aspectInterface.resumeNotification(Thread.currentThread());
128:                }
129:
130:                testObject.myFieldAccess(RUNS);
131:
132:                if (CHECK_ASSERT)
133:                    assertEquals("Hook notifications", RUNS, fieldAccessCount);
134:            }
135:
136:            public void testFieldModification0() {
137:                testObject.myFieldModification(RUNS);
138:            }
139:
140:            public void testFieldModification() {
141:                if (USE_PROSE) {
142:                    aspectInterface.setFieldModificationWatch(field,
143:                            new Object());
144:                    aspectInterface.resumeNotification(Thread.currentThread());
145:                }
146:
147:                testObject.myFieldModification(RUNS);
148:
149:                if (CHECK_ASSERT)
150:                    assertEquals("Hook notifications", RUNS,
151:                            fieldModificationCount);
152:            }
153:
154:            public void testException0() {
155:                RUNS = 1000000;
156:                testObject.myException(RUNS);
157:            }
158:
159:            public void testExceptionThrow() {
160:                if (USE_PROSE) {
161:                    aspectInterface.setExceptionThrowWatch(MyException.class,
162:                            new Object());
163:                    aspectInterface.resumeNotification(Thread.currentThread());
164:                }
165:
166:                RUNS = 1000000;
167:                testObject.myException(RUNS);
168:
169:                if (CHECK_ASSERT && USE_PROSE)
170:                    assertEquals("Hook notifications", RUNS,
171:                            exceptionThrowCount);
172:            }
173:
174:            public void testExceptionCatch() {
175:                if (USE_PROSE) {
176:                    aspectInterface.setExceptionCatchWatch(MyException.class,
177:                            new Object());
178:                    aspectInterface.resumeNotification(Thread.currentThread());
179:                }
180:
181:                RUNS = 1000000;
182:                testObject.myException(RUNS);
183:
184:                if (CHECK_ASSERT)
185:                    assertEquals("Hook notifications", RUNS,
186:                            exceptionCatchCount);
187:            }
188:
189:            public static class MyTestClass {
190:
191:                public static MyException myException = new MyException();
192:
193:                public int myField = 42;
194:
195:                public void myMethod() {
196:                }
197:
198:                public void myMethodEntry() {
199:                }
200:
201:                public void myMethodExit() {
202:                }
203:
204:                public void myMethod(int runs) {
205:                    startChronometer();
206:                    for (int i = 0; i < runs; i++)
207:                        myMethod();
208:                    stopChronometer();
209:                }
210:
211:                public void myMethodEntry(int runs) {
212:                    startChronometer();
213:                    for (int i = 0; i < runs; i++)
214:                        myMethodEntry();
215:                    stopChronometer();
216:                }
217:
218:                public void myMethodExit(int runs) {
219:                    startChronometer();
220:                    for (int i = 0; i < runs; i++)
221:                        myMethodExit();
222:                    stopChronometer();
223:                }
224:
225:                public void myFieldAccess(int runs) {
226:                    int n = 0;
227:
228:                    startChronometer();
229:                    for (int i = 0; i < runs; i++)
230:                        n = myField;
231:                    stopChronometer();
232:                }
233:
234:                public void myFieldModification(int runs) {
235:                    startChronometer();
236:                    for (int i = 0; i < runs; i++)
237:                        myField = i;
238:                    stopChronometer();
239:                }
240:
241:                public void myExceptionThrow() throws MyException {
242:                    throw myException;
243:                }
244:
245:                public void myExceptionCatch() {
246:                    try {
247:                        myExceptionThrow();
248:                    } catch (MyException e) {
249:                    }
250:                }
251:
252:                public void myException(int runs) {
253:                    MyException e = new MyException();
254:
255:                    startChronometer();
256:                    for (int i = 0; i < runs; i++)
257:                        myExceptionCatch();
258:                    stopChronometer();
259:                }
260:            }
261:
262:            public static class MyException extends Exception {
263:            };
264:
265:            public static class TestHook extends JoinPointHook {
266:
267:                public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
268:                    fieldAccessCount++;
269:                }
270:
271:                public void onFieldModification(
272:                        FieldModificationJoinPoint joinPoint) {
273:                    fieldModificationCount++;
274:                }
275:
276:                public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
277:                    methodEntryCount++;
278:                }
279:
280:                public void onMethodExit(MethodExitJoinPoint joinPoint) {
281:                    methodExitCount++;
282:                }
283:
284:                public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
285:                    exceptionThrowCount++;
286:                }
287:
288:                public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
289:                    exceptionCatchCount++;
290:                }
291:
292:                public void onClassLoad(Class cls) {
293:                }
294:
295:                public void onConstructor(ConstructorJoinPoint joinpoint) {
296:                }
297:
298:            }
299:
300:        }
301:
302:        //======================================================================
303:        //
304:        // $Log$
305:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.