curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [2/2] curator git commit: Use javaassist to make fields we're accessing volatile
Date Wed, 09 Sep 2015 18:35:28 GMT
Use javaassist to make fields we're accessing volatile


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/73b05aac
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/73b05aac
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/73b05aac

Branch: refs/heads/CURATOR-3.0
Commit: 73b05aac94099dd1c1e5684d50a51078ae844e0e
Parents: d110cbb
Author: randgalt <randgalt@apache.org>
Authored: Wed Sep 9 13:35:18 2015 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Wed Sep 9 13:35:18 2015 -0500

----------------------------------------------------------------------
 .../apache/curator/test/ByteCodeRewrite.java    | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/73b05aac/curator-test/src/main/java/org/apache/curator/test/ByteCodeRewrite.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/ByteCodeRewrite.java b/curator-test/src/main/java/org/apache/curator/test/ByteCodeRewrite.java
index eeca3d4..d8a1c3a 100644
--- a/curator-test/src/main/java/org/apache/curator/test/ByteCodeRewrite.java
+++ b/curator-test/src/main/java/org/apache/curator/test/ByteCodeRewrite.java
@@ -22,8 +22,10 @@ package org.apache.curator.test;
 import javassist.CannotCompileException;
 import javassist.ClassPool;
 import javassist.CtClass;
+import javassist.CtField;
 import javassist.CtMethod;
 import javassist.NotFoundException;
+import javassist.bytecode.AccessFlag;
 
 public class ByteCodeRewrite
 {
@@ -73,6 +75,26 @@ public class ByteCodeRewrite
             {
                 // ignore
             }
+
+            try
+            {
+                CtClass cc = pool.get("org.apache.zookeeper.server.ZooKeeperServerMain");
+                makeVolatile(cc);
+            }
+            catch ( NotFoundException e )
+            {
+                // ignore
+            }
+
+            try
+            {
+                CtClass cc = pool.get("org.apache.zookeeper.server.ServerCnxnFactory");
+                makeVolatile(cc);
+            }
+            catch ( NotFoundException e )
+            {
+                // ignore
+            }
         }
         catch ( Exception e )
         {
@@ -80,6 +102,18 @@ public class ByteCodeRewrite
         }
     }
 
+    private static void makeVolatile(CtClass cc) throws CannotCompileException
+    {
+        for ( CtField field : cc.getDeclaredFields() )
+        {
+            if ( (field.getModifiers() & (AccessFlag.ABSTRACT | AccessFlag.NATIVE | AccessFlag.SYNTHETIC
| AccessFlag.STATIC | AccessFlag.FINAL)) == 0 )
+            {
+                field.setModifiers(field.getModifiers() | AccessFlag.VOLATILE);
+            }
+        }
+        cc.toClass();
+    }
+
     private static void fixMethods(CtClass cc, String... methodNames) throws CannotCompileException
     {
         for ( CtMethod method : cc.getDeclaredMethods() )


Mime
View raw message