You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CFlowCounter.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation
  3. *
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Andy Clement initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.internal;
  14. import org.aspectj.runtime.internal.cflowstack.ThreadCounter;
  15. import org.aspectj.runtime.internal.cflowstack.ThreadStackFactory;
  16. import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl;
  17. import org.aspectj.runtime.internal.cflowstack.ThreadStackFactoryImpl11;
  18. public class CFlowCounter {
  19. private static ThreadStackFactory tsFactory;
  20. private ThreadCounter flowHeightHandler;
  21. static {
  22. selectFactoryForVMVersion();
  23. }
  24. public CFlowCounter() {
  25. flowHeightHandler = tsFactory.getNewThreadCounter();
  26. }
  27. public void inc() {
  28. flowHeightHandler.inc();
  29. }
  30. public void dec() {
  31. flowHeightHandler.dec();
  32. if (!flowHeightHandler.isNotZero()) {
  33. flowHeightHandler.removeThreadCounter();
  34. }
  35. }
  36. public boolean isValid() {
  37. return flowHeightHandler.isNotZero();
  38. }
  39. private static ThreadStackFactory getThreadLocalStackFactory() { return new ThreadStackFactoryImpl(); }
  40. private static ThreadStackFactory getThreadLocalStackFactoryFor11() { return new ThreadStackFactoryImpl11(); }
  41. private static void selectFactoryForVMVersion() {
  42. String override = getSystemPropertyWithoutSecurityException("aspectj.runtime.cflowstack.usethreadlocal","unspecified");
  43. boolean useThreadLocalImplementation = false;
  44. if (override.equals("unspecified")) {
  45. String v = System.getProperty("java.class.version","0.0");
  46. // Java 1.2 is version 46.0 and above
  47. useThreadLocalImplementation = (v.compareTo("46.0") >= 0);
  48. } else {
  49. useThreadLocalImplementation = override.equals("yes") || override.equals("true");
  50. }
  51. // System.err.println("Trying to use thread local implementation? "+useThreadLocalImplementation);
  52. if (useThreadLocalImplementation) {
  53. tsFactory = getThreadLocalStackFactory();
  54. } else {
  55. tsFactory = getThreadLocalStackFactoryFor11();
  56. }
  57. }
  58. private static String getSystemPropertyWithoutSecurityException (String aPropertyName, String aDefaultValue) {
  59. try {
  60. return System.getProperty(aPropertyName, aDefaultValue);
  61. }
  62. catch (SecurityException ex) {
  63. return aDefaultValue;
  64. }
  65. }
  66. // For debug ...
  67. public static String getThreadStackFactoryClassName() {
  68. return tsFactory.getClass().getName();
  69. }
  70. }