- The ASM library is designed to work on compiled Java classes. It was also designed to be as fast and small as possible.
- ASM provides tools to read, write and transfrom such byte arrays by using higher level concepts then bytes such as numeric constants, strings, Java identifiers, Java types, Java class structure elements.
- The ASM is just a reference to the
__asm__
keyword in C. - The core API provides an event based representation of classes, while the tree API provides an object based representation.
- The
CheckClassAdapter
class could be used to check if the bytecode generated by ASM is valid. - The
ASMifier
class could be usedd to generate the source code of ASM for generating a specific class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
eclipseHome="/home/khotyn/softwares/eclipse_java/" | |
pluginName="$1" | |
updateSiteURL="$2" | |
localRepositoryHome="/home/khotyn/softwares/eclipse_plugins/" | |
cd $eclipseHome | |
./eclipse -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication -source $updateSiteURL -destination "$localRepositoryHome$pluginName" | |
./eclipse -application org.eclipse.equinox.p2.artifact.repository.mirrorApplication -source $updateSiteURL -destination "$localRepositoryHome$pluginName" | |
echo "path=$localRepositoryHome$pluginName" > "$localRepositoryHome$pluginName.link" |
private static void makeNewClass() throws IOException, CannotCompileException {
ClassPool classPool = ClassPool.getDefault();
CtClass cc = classPool.makeClass("Test");
byte[] bytes = cc.toBytecode();
FileOutputStream fos = new FileOutputStream("/Users/apple/Desktop/Test.class");
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.khotyn.test; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Enumeration; | |
import java.util.List; | |
import java.util.jar.JarEntry; | |
import java.util.jar.JarFile; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.lang.management.ManagementFactory; | |
import java.util.Set; | |
import javax.management.MBeanServer; | |
import javax.management.ObjectName; | |
/** | |
* Print the Collector used in the program. | |
* @author khotyn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal Main | grep -P "CMSInitiatingOccupancyFraction|CMSTriggerRatio|MinHeapFreeRatio" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int hexStringToInt(String str) { | |
if (str.length() == 8) { | |
int firstBit = Integer.valueOf(str.substring(0, 1), 16); | |
if (firstBit >= 8) { | |
return Integer.valueOf((firstBit - 8) + str.substring(1), 16) - 0x80000000; | |
} else { | |
return Integer.valueOf(str, 16); | |
} | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.annotation.*; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.METHOD) | |
public @interface AnnoMethod { | |
int id() default 9; | |
String value() default "Hello, world"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.khotyn.test; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Retention(RetentionPolicy.CLASS) | |
@Target(ElementType.TYPE) | |
public @interface Anno { |