Skip to content

Commit

Permalink
Update ASM
Browse files Browse the repository at this point in the history
  • Loading branch information
T5750 committed Feb 5, 2020
1 parent dbfaab2 commit 60dde78
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion doc/source/jdk8/asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ To instrument the `java.lang.Integer` class, we **write an agent that will be co

Building and packaging our code so far produces the jar that we can load as an agent. To use our customized `Integer` class in a hypothetical `YourClass.class`:
```
java t5750.asm.instrumentation.PremainTest -javaagent:jdk8.jar
java -javaagent:jdk8.jar -cp . t5750.asm.instrument.PremainTest
```

## References
Expand Down
2 changes: 1 addition & 1 deletion jdk8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [javap](../doc/source/jdk8/javap.md)

### ASM
- [asm](../doc/source/jdk8/asm.md)
- [ASM](../doc/source/jdk8/asm.md)

### Javassist
[Javassist Tutorial](../doc/source/jdk8/javassistTutorial.md)
Expand Down
11 changes: 5 additions & 6 deletions jdk8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Premain-Class>
t5750.asm.instrumentation.Premain
</Premain-Class>
<Can-Retransform-Classes>
true
</Can-Retransform-Classes>
<Premain-Class>t5750.asm.instrument.Premain</Premain-Class>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
</manifestEntries>
</archive>
</configuration>
Expand Down
12 changes: 6 additions & 6 deletions jdk8/src/main/java/t5750/asm/CustomClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import t5750.asm.visitor.PublicizeMethodAdapter;

public class CustomClassWriter {
final static String CLASS_NAME = "java.lang.Integer";
ClassReader reader;
ClassWriter writer;
AddFieldAdapter addFieldAdapter;
PublicizeMethodAdapter pubMethAdapter;
AddInterfaceAdapter addInterfaceAdapter;
private final static String CLASS_NAME = "java.lang.Integer";
private ClassReader reader;
private ClassWriter writer;
private AddFieldAdapter addFieldAdapter;
private PublicizeMethodAdapter pubMethAdapter;
private AddInterfaceAdapter addInterfaceAdapter;

public CustomClassWriter() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package t5750.asm.instrumentation;
package t5750.asm.instrument;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;

import t5750.asm.CustomClassWriter;
import t5750.asm.util.AsmUtil;

/**
* 5. Using the Modified Class
Expand All @@ -25,6 +26,9 @@ public byte[] transform(ClassLoader l, String name, Class c,
CustomClassWriter cr = new CustomClassWriter(b);
return cr.addField();
}
if (name.equals(AsmUtil.PATH_POINT)) {
System.out.println("transform: " + name);
}
return b;
}
});
Expand Down
6 changes: 6 additions & 0 deletions jdk8/src/main/java/t5750/asm/util/AsmUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package t5750.asm.util;

public class AsmUtil {
public static final String POINT = "java.awt.Point";
public static final String PATH_POINT = POINT.replace(".", "/");
}
13 changes: 13 additions & 0 deletions jdk8/src/test/java/t5750/asm/instrument/PremainTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package t5750.asm.instrument;

import java.awt.*;

/**
* 5. Using the Modified Class
*/
public class PremainTest {
public static void main(String[] args) throws Exception {
System.out.println("PremainTest");
System.out.println(new Point().toString());
}
}
10 changes: 0 additions & 10 deletions jdk8/src/test/java/t5750/asm/instrumentation/PremainTest.java

This file was deleted.

0 comments on commit 60dde78

Please sign in to comment.