1 7 package measurements.suites; 8 9 import java.lang.reflect.Field ; 10 import java.lang.reflect.Method ; 11 12 import junit.framework.Assert; 13 import junit.framework.Test; 14 import ch.ethz.inf.util.junit.PerformanceTest; 15 import ch.ethz.inf.util.junit.PerformanceTestSuite; 16 import ch.ethz.jvmai.*; 17 18 24 public class JVMAIInfoMeasurement extends PerformanceTest { 25 26 28 29 public int theMethodToCall(int i, long l, double d, Object o) { return i; } 30 public void theMethodToCall(long i){} 31 public void theMethodToCall(Object o){} 32 public void theMethodToCall(int i){} 33 public void theMethodToCall(double d){} 34 public void theMethodToCall(){} 35 36 public int theFieldToAccess = 0; 37 38 public static class EmptyTestHook extends JoinPointHook 39 { 40 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { } 41 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 42 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { } 43 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 44 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 45 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 46 public void onClassLoad (Class cls) { } 47 } 48 49 final boolean useProse; 50 51 55 public JVMAIInfoMeasurement(String name) 56 { 57 super(name); 58 String proseParam = System.getProperty("useprose"); 59 if(proseParam==null) 60 useProse = isDebuggerEnabled(); 61 else 62 useProse = proseParam.toUpperCase().equals("TRUE"); 63 if (isDebuggerEnabled()) 64 RANGE = new int[]{ 10000}; 65 else 66 RANGE = new int[]{ 1000000 }; 67 } 68 69 JVMAspectInterface aspectInterface; 70 71 Method method,methodI,methodL,methodD,methodO,methodV; 72 Field field; 73 Object param; 74 75 protected void setUp() 76 { 77 if (!useProse) Assert.fail("unable to test info-interface if prose is disabled"); 78 try { 79 String providerName = System.getProperty("ch.ethz.prose.JVMAIProvider"); 80 Class providerClass = Class.forName(providerName); 81 Provider provider = (Provider)providerClass.newInstance(); 82 83 aspectInterface = provider.getAspectInterface(); 84 85 aspectInterface.startup(new String []{"ch.ethz.prose."},true); 86 87 method = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall", 88 new Class []{Integer.TYPE,Long.TYPE,Double.TYPE,Object .class}); 89 methodI = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{Integer.TYPE}); 90 methodL = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{Long.TYPE}); 91 methodD = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{Double.TYPE}); 92 methodO = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{Object .class}); 93 methodV = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class []{}); 94 field = JVMAIInfoMeasurement.class.getDeclaredField("theFieldToAccess"); 95 96 97 param = new String ("hello world;"); 98 EmptyTestHook hook = new EmptyTestHook(); 99 aspectInterface.setJoinPointHook(hook); 101 aspectInterface.setMethodEntryWatch(method,new Object ()); 102 aspectInterface.setMethodExitWatch(method,new Object ()); 103 104 105 aspectInterface.setFieldAccessWatch(field,new Object ()); 106 aspectInterface.setFieldModificationWatch(field,new Object ()); 107 this.theMethodToCall(1,1,1.0,param); 108 int n = this.theFieldToAccess; 109 this.theFieldToAccess = 1; 110 aspectInterface.clearMethodEntryWatch(method); 111 aspectInterface.clearMethodExitWatch(method); 112 aspectInterface.clearFieldAccessWatch(field); 113 aspectInterface.clearFieldModificationWatch(field); 114 aspectInterface.setJoinPointHook(null); 115 aspectInterface.suspendNotification(Thread.currentThread()); 116 aspectInterface.resumeNotification(Thread.currentThread()); 117 118 } catch (Exception e) { 119 Assert.fail("loading provider or initializing aspect-interface failed"); 120 } 121 } 122 123 protected void tearDown() 124 { 125 } 126 127 public void test_06_MethodEntry() 128 { 129 aspectInterface.setMethodEntryWatch(method,new Object ()); 130 EmptyTestHook hook = new EmptyTestHook(); 131 aspectInterface.setJoinPointHook(hook); 132 startChronometer(); 133 for(int i =0; i<RUNS; i++) 134 this.theMethodToCall(1,1,1.0,param); 135 stopChronometer(); 136 aspectInterface.clearMethodEntryWatch(method); 137 aspectInterface.setJoinPointHook(null); 138 } 139 140 public void test_13_MethodExit() 141 { 142 aspectInterface.setMethodExitWatch(method,new Object ()); 143 EmptyTestHook hook = new EmptyTestHook(); 144 aspectInterface.setJoinPointHook(hook); 145 startChronometer(); 146 for(int i =0; i<RUNS; i++) 147 this.theMethodToCall(1,1,1.0,param); 148 stopChronometer(); 149 aspectInterface.clearMethodExitWatch(method); 150 aspectInterface.setJoinPointHook(null); 151 } 152 153 public void test_15_FieldAccess() 154 { 155 aspectInterface.setFieldAccessWatch(field,new Object ()); 156 EmptyTestHook hook = new EmptyTestHook(); 157 aspectInterface.setJoinPointHook(hook); 158 int n = 0; 159 startChronometer(); 160 for(int i =0; i<RUNS; i++) 161 n = this.theFieldToAccess; 162 stopChronometer(); 163 aspectInterface.clearFieldAccessWatch(field); 164 aspectInterface.setJoinPointHook(null); 165 } 166 167 public void test_18_FieldModification() 168 { 169 aspectInterface.setFieldModificationWatch(field,new Object ()); 170 EmptyTestHook hook = new EmptyTestHook(); 171 aspectInterface.setJoinPointHook(hook); 172 startChronometer(); 173 for(int i =0; i<RUNS; i++) 174 this.theFieldToAccess = 1; 175 stopChronometer(); 176 aspectInterface.clearFieldModificationWatch(field); 177 aspectInterface.setJoinPointHook(null); 178 } 179 180 181 182 183 184 185 186 188 public static class LocalVariableTestHook extends JoinPointHook 189 { 190 public LocalVariableTestHook() {} 191 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { } 192 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 193 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { 194 joinPoint.getArgs(); 195 } 196 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 197 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 198 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 199 public void onClassLoad (Class cls) { } 200 201 } 202 203 public void test_08_GetLocalVariableValue_int() 204 { 205 aspectInterface.setMethodEntryWatch(methodI,new Object ()); 206 LocalVariableTestHook hook = new LocalVariableTestHook(); 207 aspectInterface.setJoinPointHook(hook); 208 startChronometer(); 209 int param =1 ; 210 for(int i =0; i<RUNS; i++) 211 this.theMethodToCall(i); 212 stopChronometer(); 213 aspectInterface.clearMethodEntryWatch(methodI); aspectInterface.setJoinPointHook(null); 214 } 215 216 public void test_09_GetLocalVariableValue_long() 217 { 218 long longParam = 1; 219 aspectInterface.setMethodEntryWatch(methodL,new Object ()); 220 LocalVariableTestHook hook = new LocalVariableTestHook(); 221 aspectInterface.setJoinPointHook(hook); 222 startChronometer(); 223 for(int i =0; i<RUNS; i++) 224 this.theMethodToCall(longParam); 225 stopChronometer(); 226 aspectInterface.clearMethodEntryWatch(methodL); 227 aspectInterface.setJoinPointHook(null); 228 } 229 230 public void test_10_GetLocalVariableValue_double() 231 { 232 double doubleParam = 12.0; 233 aspectInterface.setMethodEntryWatch(methodD,new Object ()); 234 LocalVariableTestHook hook = new LocalVariableTestHook(); 235 aspectInterface.setJoinPointHook(hook); 236 startChronometer(); 237 for(int i =0; i<RUNS; i++) 238 this.theMethodToCall(doubleParam); 239 stopChronometer(); 240 aspectInterface.clearMethodEntryWatch(methodD); 241 aspectInterface.setJoinPointHook(null); 242 } 243 244 public void test_11_GetLocalVariableValue_Object() 245 { 246 Object objectParam = new Object (); 247 aspectInterface.setMethodEntryWatch(methodO,new Object ()); 248 LocalVariableTestHook hook = new LocalVariableTestHook(); 249 aspectInterface.setJoinPointHook(hook); 250 startChronometer(); 251 for(int i =0; i<RUNS; i++) 252 this.theMethodToCall(objectParam); 253 stopChronometer(); 254 aspectInterface.clearMethodEntryWatch(methodO); 255 aspectInterface.setJoinPointHook(null); 256 } 257 258 260 public static class ThisValueTestHook extends JoinPointHook 261 { 262 263 public ThisValueTestHook() { } 264 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { } 265 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 266 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { 267 joinPoint.getThis(); 268 } 269 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 270 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 271 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 272 public void onClassLoad (Class cls) { } 273 } 274 275 public void test_12_GetThisValue() 276 { 277 aspectInterface.setMethodEntryWatch(method,new Object ()); 278 ThisValueTestHook hook = new ThisValueTestHook(); 279 aspectInterface.setJoinPointHook(hook); 280 startChronometer(); 281 for(int i =0; i<RUNS; i++) 282 this.theMethodToCall(1,1,1.0,param); 283 stopChronometer(); 284 aspectInterface.clearMethodEntryWatch(method); 285 aspectInterface.setJoinPointHook(null); 286 } 287 288 290 public static class ReturnValueTestHook extends JoinPointHook 291 { 292 293 public ReturnValueTestHook() { } 294 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { } 295 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 296 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { } 297 public void onMethodExit (MethodExitJoinPoint joinPoint) { 298 joinPoint.getResult(); 299 } 300 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 301 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 302 public void onClassLoad (Class cls) { } 303 } 304 305 public void test_14_GetReturnValue() 306 { 307 aspectInterface.setMethodExitWatch(method,new Object ()); 308 ReturnValueTestHook hook = new ReturnValueTestHook(); 309 aspectInterface.setJoinPointHook(hook); 310 startChronometer(); 311 for(int i =0; i<RUNS; i++) 312 this.theMethodToCall(1,1,1.0,param); 313 stopChronometer(); 314 aspectInterface.clearMethodExitWatch(method); 315 aspectInterface.setJoinPointHook(null); 316 } 317 318 320 public static class FieldOwnerTestHook extends JoinPointHook 321 { 322 323 public FieldOwnerTestHook() { } 324 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { 325 joinPoint.getTarget(); 326 } 327 public void onFieldModification(FieldModificationJoinPoint joinPoint) { } 328 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { } 329 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 330 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 331 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 332 public void onClassLoad (Class cls) { } 333 } 334 335 public void test_16_GetFieldOwner() 336 { 337 aspectInterface.setFieldAccessWatch(field,new Object ()); 338 FieldOwnerTestHook hook = new FieldOwnerTestHook(); 339 aspectInterface.setJoinPointHook(hook); 340 int n = 0; 341 startChronometer(); 342 for(int i =0; i<RUNS; i++) 343 n = this.theFieldToAccess; 344 stopChronometer(); 345 aspectInterface.clearFieldAccessWatch(field); 346 aspectInterface.setJoinPointHook(null); 347 } 348 349 351 public static class FieldValueTestHook extends JoinPointHook 352 { 353 354 public FieldValueTestHook() { } 355 public void onFieldAccess (FieldAccessJoinPoint joinPoint) { 356 joinPoint.getValue(); 357 } 358 public void onFieldModification(FieldModificationJoinPoint joinPoint) { 359 joinPoint.getNewValue(); 360 } 361 public void onMethodEntry (MethodEntryJoinPoint joinPoint) { } 362 public void onMethodExit (MethodExitJoinPoint joinPoint) { } 363 public void onExceptionThrow (ExceptionJoinPoint joinPoint) { } 364 public void onExceptionCatch (ExceptionCatchJoinPoint joinPoint) { } 365 public void onClassLoad (Class cls) { } 366 } 367 368 public void test_17_GetFieldValue() 369 { 370 aspectInterface.setFieldAccessWatch(field,new Object ()); 371 FieldValueTestHook hook = new FieldValueTestHook(); 372 aspectInterface.setJoinPointHook(hook); 373 int n = 0; 374 startChronometer(); 375 for(int i =0; i<RUNS; i++) 376 n = this.theFieldToAccess; 377 stopChronometer(); 378 aspectInterface.clearFieldAccessWatch(field); 379 aspectInterface.setJoinPointHook(null); 380 } 381 382 public void test_19_GetNewFieldValue() 383 { 384 aspectInterface.setFieldModificationWatch(field,new Object ()); 385 FieldValueTestHook hook = new FieldValueTestHook(); 386 aspectInterface.setJoinPointHook(hook); 387 startChronometer(); 388 for(int i =0; i<RUNS; i++) 389 this.theFieldToAccess = 1; 390 stopChronometer(); 391 aspectInterface.clearFieldModificationWatch(field); 392 aspectInterface.setJoinPointHook(null); 393 } 394 395 396 404 405 407 411 public static Test suite() 412 { 413 return new PerformanceTestSuite(JVMAIInfoMeasurement.class); 414 } 415 416 } 417 418 419 | Popular Tags |