8010209: Better provision of factories
authorjbachorik
Wed, 27 Mar 2013 13:29:22 +0100
changeset 18208 5c6150ffbc80
parent 18207 64dcc0ad2298
child 18209 6d003de63e55
8010209: Better provision of factories Reviewed-by: dcubed, ahgross
jdk/src/share/classes/sun/tracing/ProviderSkeleton.java
jdk/src/share/classes/sun/tracing/dtrace/DTraceProvider.java
--- a/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java	Wed Mar 27 09:59:17 2013 +0100
+++ b/jdk/src/share/classes/sun/tracing/ProviderSkeleton.java	Wed Mar 27 13:29:22 2013 +0100
@@ -154,20 +154,25 @@
      * @return always null, if the method is a user-defined probe
      */
     public Object invoke(Object proxy, Method method, Object[] args) {
-        if (method.getDeclaringClass() != providerType) {
+        Class declaringClass = method.getDeclaringClass();
+        // not a provider subtype's own method
+        if (declaringClass != providerType) {
             try {
-                return method.invoke(this, args);
+                // delegate only to methods declared by
+                // com.sun.tracing.Provider or java.lang.Object
+                if (declaringClass == Provider.class ||
+                    declaringClass == Object.class) {
+                    return method.invoke(this, args);
+                } else {
+                    assert false;
+                }
             } catch (IllegalAccessException e) {
                 assert false;
             } catch (InvocationTargetException e) {
                 assert false;
             }
-        } else if (active) {
-            ProbeSkeleton p = probes.get(method);
-            if (p != null) {
-                // Skips argument check -- already done by javac
-                p.uncheckedTrigger(args);
-            }
+        } else {
+            triggerProbe(method, args);
         }
         return null;
     }
@@ -252,4 +257,14 @@
         }
         return ret;
     }
+
+    protected void triggerProbe(Method method, Object[] args) {
+        if (active) {
+            ProbeSkeleton p = probes.get(method);
+            if (p != null) {
+                // Skips argument check -- already done by javac
+                p.uncheckedTrigger(args);
+            }
+        }
+    }
 }
--- a/jdk/src/share/classes/sun/tracing/dtrace/DTraceProvider.java	Wed Mar 27 09:59:17 2013 +0100
+++ b/jdk/src/share/classes/sun/tracing/dtrace/DTraceProvider.java	Wed Mar 27 13:29:22 2013 +0100
@@ -151,19 +151,8 @@
     // directly.  So this method should never get invoked.  We also wire up the
     // DTraceProbe.uncheckedTrigger() method to call the proxy method instead
     // of doing the work itself.
-    public Object invoke(Object proxy, Method method, Object[] args) {
-        if (method.getDeclaringClass() != providerType) {
-            try {
-                return method.invoke(this, args);
-            } catch (IllegalAccessException e) {
-                assert false;
-            } catch (InvocationTargetException e) {
-                assert false;
-            }
-        } else if (active) {
-            assert false : "This method should have been overridden by the JVM";
-        }
-        return null;
+    protected void triggerProbe(Method method, Object[] args) {
+        assert false : "This method should have been overridden by the JVM";
     }
 
     public String getProviderName() {