sirona-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1657462 - in /incubator/sirona/trunk/agent/javaagent: ./ src/main/java/org/apache/sirona/javaagent/ src/test/java/org/apache/test/sirona/javaagent/
Date Thu, 05 Feb 2015 03:35:37 GMT
Author: olamy
Date: Thu Feb  5 03:35:36 2015
New Revision: 1657462

URL: http://svn.apache.org/r1657462
Log:
implement passing array with method args to the Agent contxxt

Modified:
    incubator/sirona/trunk/agent/javaagent/pom.xml
    incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/AgentContext.java
    incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaClassVisitor.java
    incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaTransformer.java
    incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/AgentPerfInterceptorAgentContractTest.java
    incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/App.java
    incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/PathTrackingListenerTest.java

Modified: incubator/sirona/trunk/agent/javaagent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/pom.xml?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/pom.xml (original)
+++ incubator/sirona/trunk/agent/javaagent/pom.xml Thu Feb  5 03:35:36 2015
@@ -188,6 +188,7 @@
             <test.debug.remote>${test.debug.remote}</test.debug.remote>
             <project.build.directory>${project.build.directory}</project.build.directory>
             <sirona.agent.debug>${sirona.agent.debug}</sirona.agent.debug>
+            <java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
           </systemPropertyVariables>
         </configuration>
       </plugin>

Modified: incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/AgentContext.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/AgentContext.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/AgentContext.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/AgentContext.java
Thu Feb  5 03:35:36 2015
@@ -70,8 +70,9 @@ public class AgentContext {
         return AGENT_PARAMETERS;
     }
 
+
     // called by agent
-    public static AgentContext startOn(final Object that, final String key) {
+    public static AgentContext startOn(final Object that, final String key, final Object[]
methodParameters) {
 		if (key == null) { // possible in static inits, the best would be to ignore it in instrumentation
 			return FAKE_CONTEXT;
 		}

Modified: incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaClassVisitor.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaClassVisitor.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaClassVisitor.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaClassVisitor.java
Thu Feb  5 03:35:36 2015
@@ -18,6 +18,7 @@ package org.apache.sirona.javaagent;
 
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Handle;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -26,6 +27,7 @@ import org.objectweb.asm.commons.AdviceA
 import org.objectweb.asm.commons.Method;
 
 import java.lang.reflect.Modifier;
+import java.util.Arrays;
 
 import static java.lang.Integer.MIN_VALUE;
 
@@ -108,34 +110,71 @@ public class SironaClassVisitor extends
         private final boolean isStatic;
         private final String label;
         private final String desc;
+        private final int access;
 
         public SironaAdviceAdapter(final MethodVisitor visitor, final int access, final String
name, final String desc, final String label) {
             super(ASM5, visitor, access, name, desc);
             this.isStatic = Modifier.isStatic(access);
             this.label = label;
             this.desc = desc;
+            this.access = access;
         }
 
         private int ctxLocal;
         private final Label tryStart = new Label();
         private final Label endLabel = new Label();
 
+
+
         @Override
         public void onMethodEnter() {
-            if (isStatic) {
-                visitInsn(ACONST_NULL);
-            } else {
+
+            // we need to call static method onStart from AgentContext
+            // with parameters final Object that, final String key, final Object[] methodParameters
+
+            if ( isStatic )
+            {
+                visitInsn( ACONST_NULL );
+            }
+            else
+            {
                 loadThis();
             }
-            push(label);
 
-            ctxLocal = newLocal(AGENT_CONTEXT);
-            invokeStatic(AGENT_CONTEXT, START_METHOD);
-            storeLocal(ctxLocal);
+            push( label );
+
+            int length = Type.getArgumentTypes( desc ).length;
 
-            visitLabel(tryStart);
+            // push count of arguments to the stack
+            super.visitIntInsn( BIPUSH, length );
+            // creates an object array
+            super.visitTypeInsn( ANEWARRAY, "java/lang/Object" );
+
+            // stores the arguments in the array
+            for ( int i = 0; i < length; i++ )
+            {
+                // duplicates the reference to the array. AASTORE consumes the stack element
with the reference to the array.
+                super.visitInsn( DUP );
+                // could be optimized
+                super.visitIntInsn( BIPUSH, i );
+                // puts the value of the current argument on the stack
+                super.visitVarInsn( ALOAD, i + ( isStatic ? 0 : 1 ) );
+                // stores the value of the current argument in the array
+                super.visitInsn( AASTORE );
+            }
+
+            ctxLocal = newLocal( AGENT_CONTEXT );
+
+            invokeStatic( AGENT_CONTEXT, START_METHOD );
+
+            //visitMethodInsn(INVOKESTATIC, "org/apache/sirona/javaagent/AgentContext", "startOn",
"(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V", false);
+
+            storeLocal( ctxLocal );
+
+            visitLabel( tryStart );
         }
 
+
         @Override
         public void onMethodExit(final int opCode) {
             if (opCode == ATHROW) {

Modified: incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaTransformer.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaTransformer.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaTransformer.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/main/java/org/apache/sirona/javaagent/SironaTransformer.java
Thu Feb  5 03:35:36 2015
@@ -53,9 +53,10 @@ public class SironaTransformer implement
 
             if (advisor.wasAdviced()) {
                 final byte[] bytes = writer.toByteArray();
-                if (debug) {
+                //if (debug) {
                     final File dump = new File(System.getProperty("java.io.tmpdir"), "sirona-dump/"
+ className + ".class");
                     dump.getParentFile().mkdirs();
+                System.out.println( "dump to:" + dump.getPath() );
                     FileOutputStream w = null;
                     try {
                         w = new FileOutputStream(dump);
@@ -65,7 +66,7 @@ public class SironaTransformer implement
                             w.close();
                         }
                     }
-                }
+                //}
                 return bytes;
             }
             return classfileBuffer;

Modified: incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/AgentPerfInterceptorAgentContractTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/AgentPerfInterceptorAgentContractTest.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/AgentPerfInterceptorAgentContractTest.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/AgentPerfInterceptorAgentContractTest.java
Thu Feb  5 03:35:36 2015
@@ -36,7 +36,7 @@ public class AgentPerfInterceptorAgentCo
     public void start() {
         final String key = "start";
         AgentContext.listeners(key, new byte[0]);
-        final AgentContext context = AgentContext.startOn(null, key);
+        final AgentContext context = AgentContext.startOn(null, key, null);
         context.stop(null);
         assertEquals("org.apache.sirona.javaagent.AgentContext", context.getClass().getName());
         assertEquals(1, Repository.INSTANCE.getCounter(AgentContext.key(key)).getHits());
@@ -47,7 +47,7 @@ public class AgentPerfInterceptorAgentCo
         final String key = "ref";
         final Object instance = new Object();
         AgentContext.listeners(key, new byte[0]);
-        final AgentContext context = AgentContext.startOn(instance, key);
+        final AgentContext context = AgentContext.startOn(instance, key, null);
         context.stop(null);
         assertEquals(instance, context.getReference());
         assertEquals(key, context.getKey());

Modified: incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/App.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/App.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/App.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/App.java
Thu Feb  5 03:35:36 2015
@@ -35,20 +35,21 @@ public class App
         throws Exception
     {
         this.foo();
-        this.pub();
+        this.pub( "blabla" );
     }
 
-    public void pub()
+    public void pub( String foo )
         throws Exception
     {
         Thread.sleep( 100 );
         this.bar();
     }
 
-    public void bar()
+    public App bar()
         throws Exception
     {
         Thread.sleep( 300 );
+        return this;
     }
 
 

Modified: incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/PathTrackingListenerTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/PathTrackingListenerTest.java?rev=1657462&r1=1657461&r2=1657462&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/PathTrackingListenerTest.java
(original)
+++ incubator/sirona/trunk/agent/javaagent/src/test/java/org/apache/test/sirona/javaagent/PathTrackingListenerTest.java
Thu Feb  5 03:35:36 2015
@@ -42,7 +42,7 @@ public class PathTrackingListenerTest
 
     @Test
     @AgentArgs(value = "",
-               sysProps = "project.build.directory=${project.build.directory}|sirona.agent.debug=${sirona.agent.debug}|org.apache.sirona.configuration.sirona.properties=${project.build.directory}/test-classes/pathtracking/sirona.properties")
+               sysProps = "project.build.directory=${project.build.directory}|sirona.agent.debug=${sirona.agent.debug}|org.apache.sirona.configuration.sirona.properties=${project.build.directory}/test-classes/pathtracking/sirona.properties|java.io.tmpdir=${java.io.tmpdir}")
     public void simpleTest()
         throws Exception
     {



Mime
View raw message