[jaxb~v2:a7ff7233] remove the need for synchronization - tailor can still happen multiple ti

  • From: snajper@...
  • To: commits@...
  • Subject: [jaxb~v2:a7ff7233] remove the need for synchronization - tailor can still happen multiple ti
  • Date: Thu, 22 Aug 2013 15:41:21 +0000

Project:    jaxb
Repository: v2
Revision:   a7ff7233ee70cddab86afd739ad59b8f95904a90
Author:     snajper
Date:       2013-08-22 15:26:28 UTC
Link:       

Log Message:
------------
touched code - minor improvements
remove the need for synchronization - tailor can still happen multiple times 
under specific circumstances, but it's better than contention within multiple 
threads on one class
remove the need for synchronization - tailor can still happen multiple times 
under specific circumstances, but it's better than contention within multiple 
threads on one class


Revisions:
----------
77094c1f3b6ec9e9149330c61276417cbeaf24f1
5c129cd003227735ab7cb85ed37e73bf3d7dfce5
a7ff7233ee70cddab86afd739ad59b8f95904a90


Modified Paths:
---------------
jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/Injector.java
jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/OptimizedAccessorFactory.java
jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/AccessorInjector.java


Diffs:
------
--- 
a/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/Injector.java
+++ 
b/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/Injector.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -171,6 +171,7 @@ final class Injector {
         }
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 
+            @Override
             public Void run() {
                 // TODO: check security implication
                 // do these setAccessible allow anyone to call these methods 
freely?s--- 
a/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/OptimizedAccessorFactory.java
+++ 
b/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/OptimizedAccessorFactory.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -142,8 +142,11 @@ public abstract class OptimizedAccessorFactory {
             return null;
 
         Accessor<B,V> acc = instanciate(opt);
-        if(acc!=null)
-            logger.log(Level.FINE,"Using optimized Accessor for "+getter+" 
and "+setter);
+        if (acc!=null) {
+            if (logger.isLoggable(Level.FINE)) {
+                logger.log(Level.FINE, "Using optimized Accessor for {0} and 
{1}", new Object[]{getter, setter});
+            }
+        }
         return acc;
     }
 
@@ -189,8 +192,11 @@ public abstract class OptimizedAccessorFactory {
             return null;
 
         Accessor<B,V> acc = instanciate(opt);
-        if(acc!=null)
-            logger.log(Level.FINE,"Using optimized Accessor for "+field);
+        if (acc!=null) {
+            if (logger.isLoggable(Level.FINE)) {
+                logger.log(Level.FINE, "Using optimized Accessor for {0}", 
field);
+            }
+        }
         return acc;
     }
 

--- 
a/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/AccessorInjector.java
+++ 
b/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/AccessorInjector.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -78,19 +78,15 @@ class AccessorInjector {
             ClassLoader cl = beanClass.getClassLoader();
             if(cl==null)    return null;    // how do I inject classes to 
this "null" class loader? for now, back off.
 
-            Class c = null;
-            synchronized (AccessorInjector.class) {
-                c = Injector.find(cl,newClassName);
-                if(c==null) {
-                    byte[] image = 
tailor(templateClassName,newClassName,replacements);
-    //                try {
-    //                    new FileOutputStream("debug.class").write(image);
-    //                } catch (IOException e) {
-    //                    e.printStackTrace();
-    //                }
-                    if(image==null)
-                        return null;
-                    c = Injector.inject(cl,newClassName,image);
+            Class c = Injector.find(cl,newClassName);
+            if (c==null) {
+                byte[] image = 
tailor(templateClassName,newClassName,replacements);
+                if (image==null) {
+                    return null;
+                }
+                c = Injector.inject(cl,newClassName,image);
+                if (c == null) {
+                    Injector.find(cl, newClassName);
                 }
             }
             return c;
@@ -126,5 +122,19 @@ class AccessorInjector {
         return 
ClassTailor.tailor(resource,templateClassName,newClassName,replacements);
     }
 
-    private static final ClassLoader CLASS_LOADER = 
AccessorInjector.class.getClassLoader();
+    private static final ClassLoader CLASS_LOADER = 
SecureLoader.getClassClassLoader(AccessorInjector.class);
+    
+    private class ClassWithinClassloader {
+        private ClassLoader cl;
+        private String className;
+
+        private ClassWithinClassloader() {}
+        
+        private ClassWithinClassloader(ClassLoader cl, String className) {
+            this.cl = cl;
+            this.className = className;
+        }
+
+    }
+
 }

--- 
a/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/AccessorInjector.java
+++ 
b/jaxb-ri/runtime/src/com/sun/xml/bind/v2/runtime/reflect/opt/AccessorInjector.java
@@ -124,17 +124,4 @@ class AccessorInjector {
 
     private static final ClassLoader CLASS_LOADER = 
SecureLoader.getClassClassLoader(AccessorInjector.class);
     
-    private class ClassWithinClassloader {
-        private ClassLoader cl;
-        private String className;
-
-        private ClassWithinClassloader() {}
-        
-        private ClassWithinClassloader(ClassLoader cl, String className) {
-            this.cl = cl;
-            this.className = className;
-        }
-
-    }
-
 }





[jaxb~v2:a7ff7233] remove the need for synchronization - tailor can still happen multiple ti

snajper 08/22/2013
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150626.29986a4)
 
 
Close
loading
Please Confirm
Close