aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs196
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2020-04-29 15:14:34 -0700
committerAndy Clement <aclement@pivotal.io>2020-04-29 15:14:34 -0700
commitebc1e849d3ebfb67645816f356e4b99b4d22196c (patch)
treebcb739ff30624880b14529d8c1ab6011b9c3e1de /tests/bugs196
parent869b7cccd343d3771964f0f198522a0fac64d808 (diff)
downloadaspectj-ebc1e849d3ebfb67645816f356e4b99b4d22196c.tar.gz
aspectj-ebc1e849d3ebfb67645816f356e4b99b4d22196c.zip
558995 testcode
Diffstat (limited to 'tests/bugs196')
-rw-r--r--tests/bugs196/558995/foo/Synchronized.java5
-rw-r--r--tests/bugs196/558995/foo/SynchronizedAspect.aj91
-rw-r--r--tests/bugs196/558995/foo/SynchronizedStaticAspect.aj98
-rw-r--r--tests/bugs196/558995/foo/SynchronizedTest.java27
4 files changed, 221 insertions, 0 deletions
diff --git a/tests/bugs196/558995/foo/Synchronized.java b/tests/bugs196/558995/foo/Synchronized.java
new file mode 100644
index 000000000..9dcf09fa2
--- /dev/null
+++ b/tests/bugs196/558995/foo/Synchronized.java
@@ -0,0 +1,5 @@
+package foo;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface Synchronized {}
diff --git a/tests/bugs196/558995/foo/SynchronizedAspect.aj b/tests/bugs196/558995/foo/SynchronizedAspect.aj
new file mode 100644
index 000000000..127778742
--- /dev/null
+++ b/tests/bugs196/558995/foo/SynchronizedAspect.aj
@@ -0,0 +1,91 @@
+package foo;
+
+import org.aspectj.lang.annotation.SuppressAjWarnings;
+
+public aspect SynchronizedAspect perthis(@this(Synchronized)) {
+
+// private static final Logger log = LogManager.getLogger(SynchronizedAspect.class);
+// private Lock objectLock = new ReentrantLock();
+// private static long timeout = 1800;
+// private static TimeUnit unit = TimeUnit.SECONDS;
+// private static boolean timeoutInitialized = false;
+
+// @SuppressWarnings({"rawtypes"})
+// private final static synchronized void initTimeout(Class cl) {
+// timeout = SynchronizedStaticAspect.aspectOf(cl).timeout;
+// unit = SynchronizedStaticAspect.aspectOf(cl).unit;
+// timeoutInitialized = true;
+// log.trace("timeout inialized with " + timeout + " " + unit);
+// }
+
+ pointcut synchronizedMethods() :
+ execution(@Synchronized !synchronized !static * *..*.*(..))
+ ;
+
+ pointcut synchronizedStaticMethods() :
+ execution(@Synchronized !synchronized static * *..*.*(..))
+ ;
+
+ pointcut ignoredSynchronized() :
+ execution(@Synchronized * *..*.*(..))
+ && !synchronizedMethods()
+ && !synchronizedStaticMethods()
+ ;
+
+ declare warning : ignoredSynchronized() :
+ "@Synchronized is ignored here";
+
+ declare warning :
+ (synchronizedStaticMethods() || synchronizedMethods())
+ && !@within(Synchronized) :
+ "@Synchronized is ignored here because @Synchronized for class is missing";
+
+ /**
+ * Uses the Lock class of Java 5 to put a synchronization wrapper around
+ * a method. Advantage of this Lock class is the posibility to use a
+ * timeout to avoid dead locks.
+ *
+ * @return the return value of the wrapped method
+ */
+ @SuppressAjWarnings({"adviceDidNotMatch"})
+ Object around() : synchronizedMethods() && @within(Synchronized) {
+return proceed();
+/*
+ if (!timeoutInitialized) {
+ initTimeout(thisJoinPointStaticPart.getSignature().getDeclaringType());
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("synchronizing " + thisJoinPoint.getSignature().toShortString() + "...");
+ }
+ try {
+ if (objectLock.tryLock(timeout, unit)) {
+ if (log.isTraceEnabled()) {
+ log.trace("lock granted for "
+ + thisJoinPoint.getSignature().toShortString());
+ }
+ try {
+ return proceed();
+ } finally {
+ objectLock.unlock();
+ if (log.isTraceEnabled()) {
+ log.trace("lock released for "
+ + thisJoinPoint.getSignature().toShortString());
+ }
+ }
+ } else {
+ String msg = "can't get " + objectLock + " for "
+ + thisJoinPoint.getSignature().toShortString()
+ + " after " + timeout + " " + unit;
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
+ } catch (InterruptedException ie) {
+ String msg = "interrupted: "
+ + thisJoinPoint.getSignature().toShortString();
+ log.warn(msg, ie);
+ throw new RuntimeException(msg, ie);
+ }
+*/
+ }
+
+}
diff --git a/tests/bugs196/558995/foo/SynchronizedStaticAspect.aj b/tests/bugs196/558995/foo/SynchronizedStaticAspect.aj
new file mode 100644
index 000000000..d8ff5ec2a
--- /dev/null
+++ b/tests/bugs196/558995/foo/SynchronizedStaticAspect.aj
@@ -0,0 +1,98 @@
+package foo;
+
+/**
+ * For synchronization we synchronize each static method mark as @Synchronized
+ * by a ReentrantLock.
+ *
+ * @author <a href="boehm@javatux.de">oliver</a>
+ * @since 0.8
+ */
+import org.aspectj.lang.annotation.SuppressAjWarnings;
+
+public aspect SynchronizedStaticAspect pertypewithin(@Synchronized *) {
+
+/*
+ private static final Logger log = LogManager.getLogger(SynchronizedStaticAspect.class);
+ private Lock classLock = new ReentrantLock();
+ protected long timeout = 1800;
+ protected TimeUnit unit = TimeUnit.SECONDS;
+
+*/
+ /**
+ * This advice is used to get the timeout value for the wrapped static
+ * methods.
+ *
+ * @param t the annotation with the timeout value
+ */
+ before(Synchronized t) :
+ staticinitialization(@Synchronized *) && @annotation(t) {
+/*
+ this.timeout = t.timeout();
+ this.unit = t.unit();
+ if (log.isTraceEnabled()) {
+ log.trace("lock timeout for "
+ + thisJoinPointStaticPart.getSignature().getDeclaringType().getSimpleName()
+ + " set to " + this.timeout + " " + this.unit);
+ }
+*/
+ }
+
+
+private Log log = new Log();
+static class Log {
+ public boolean isTraceEnabled() { return true;}
+ public void trace(String s) {}
+ public void error(String s) {}
+ public void warn(String s,InterruptedException ie) {}
+
+}
+ClassLock classLock = new ClassLock();
+static class ClassLock {
+ public boolean tryLock(Object o, Object b) {
+return true;
+}
+public void unlock(){}
+}
+String timeout="";
+String unit="";
+ /**
+ * This is the synchronization wrapper for the static methods which are
+ * synchronized by a ReentrantLock class.
+ *
+ * @return the return value of the static method
+ */
+@SuppressAjWarnings
+ Object around() : SynchronizedAspect.synchronizedStaticMethods() {
+ if (log.isTraceEnabled()) {
+ log.trace("synchronizing " + thisJoinPointStaticPart.getSignature().toShortString() + "...");
+ }
+ try {
+ if (classLock.tryLock(timeout, unit)) {
+ if (log.isTraceEnabled()) {
+ log.trace("lock granted for "
+ + thisJoinPointStaticPart.getSignature().toShortString());
+ }
+ try {
+ return proceed();
+ } finally {
+ classLock.unlock();
+ if (log.isTraceEnabled()) {
+ log.trace("lock released for "
+ + thisJoinPointStaticPart.getSignature().toShortString());
+ }
+ }
+ } else {
+ String msg = "can't get " + classLock + " for "
+ + thisJoinPointStaticPart.getSignature().toShortString();
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
+ } catch (InterruptedException ie) {
+ String msg = "interrupted: "
+ + thisJoinPoint.getSignature().toShortString();
+ log.warn(msg, ie);
+ throw new RuntimeException(msg, ie);
+ }
+ }
+
+}
diff --git a/tests/bugs196/558995/foo/SynchronizedTest.java b/tests/bugs196/558995/foo/SynchronizedTest.java
new file mode 100644
index 000000000..dfe62fd23
--- /dev/null
+++ b/tests/bugs196/558995/foo/SynchronizedTest.java
@@ -0,0 +1,27 @@
+package foo;
+
+//@ProfileMe
+//@ThreadSafe
+@Synchronized//(timeout = 2, unit = TimeUnit.SECONDS)
+public final class SynchronizedTest { //implements Runnable {
+
+
+ @Synchronized
+ public void incrementCounter() {
+/*
+ int n = counter;
+ log.debug("counter read (" + n + ")");
+ ThreadUtil.sleep();
+ n++;
+ log.debug("counter increased (" + n + ")");
+ ThreadUtil.sleep();
+ counter = n;
+ log.debug("counter written (" + n + ")");
+*/
+ }
+
+ public void run() {
+ // incrementCounter();
+ }
+
+}