1 13 14 15 package org.aspectj.runtime.internal; 16 17 import org.aspectj.runtime.internal.cflowstack.ThreadCounter; 18 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory; 19 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl; 20 import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11; 21 22 23 public class CFlowCounter { 24 25 private static ThreadStackFactory tsFactory; 26 private ThreadCounter flowHeightHandler; 27 28 static { 29 selectFactoryForVMVersion(); 30 } 31 32 public CFlowCounter() { 33 flowHeightHandler = tsFactory.getNewThreadCounter(); 34 } 35 36 public void inc() { 37 flowHeightHandler.inc(); 38 } 39 40 public void dec() { 41 flowHeightHandler.dec(); 42 } 43 44 public boolean isValid() { 45 return flowHeightHandler.isNotZero(); 46 } 47 48 49 private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); } 50 private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); } 51 52 private static void selectFactoryForVMVersion() { 53 String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified"); 54 boolean useThreadLocalImplementation = false; 55 if (override.equals("unspecified")) { 56 String v = System.getProperty("java.class.version","0.0"); 57 useThreadLocalImplementation = (v.compareTo("46.0") >= 0); 59 } else { 60 useThreadLocalImplementation = override.equals("yes") || override.equals("true"); 61 } 62 if (useThreadLocalImplementation) { 64 tsFactory = getThreadLocalStackFactory(); 65 } else { 66 tsFactory = getThreadLocalStackFactoryFor11(); 67 } 68 } 69 70 71 private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) { 72 try { 73 return System.getProperty(aPropertyName, aDefaultValue); 74 } 75 catch (SecurityException ex) { 76 return aDefaultValue; 77 } 78 } 79 80 public static String getThreadStackFactoryClassName() { 82 return tsFactory.getClass().getName(); 83 } 84 85 } 86 | Popular Tags |