Java源码示例:jdk.internal.org.objectweb.asm.util.CheckClassAdapter
示例1
public static void writeGeneratedASM(String className, byte[] bytes) {
if (SAVE_GENERATED == null) {
// We can't calculate value statically because it will force
// initialization of SecuritySupport, which cause
// UnsatisfiedLinkedError on JDK 8 or non-Oracle JDKs
SAVE_GENERATED = SecuritySupport.getBooleanProperty("jfr.save.generated.asm");
}
if (SAVE_GENERATED) {
try {
try (FileOutputStream fos = new FileOutputStream(className + ".class")) {
fos.write(bytes);
}
try (FileWriter fw = new FileWriter(className + ".asm"); PrintWriter pw = new PrintWriter(fw)) {
ClassReader cr = new ClassReader(bytes);
CheckClassAdapter.verify(cr, true, pw);
}
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Instrumented code saved to " + className + ".class and .asm");
} catch (IOException e) {
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Could not save instrumented code, for " + className + ".class and .asm");
}
}
}
示例2
public static void writeGeneratedASM(String className, byte[] bytes) {
if (SAVE_GENERATED == null) {
// We can't calculate value statically because it will force
// initialization of SecuritySupport, which cause
// UnsatisfiedLinkedError on JDK 8 or non-Oracle JDKs
SAVE_GENERATED = SecuritySupport.getBooleanProperty("jfr.save.generated.asm");
}
if (SAVE_GENERATED) {
try {
try (FileOutputStream fos = new FileOutputStream(className + ".class")) {
fos.write(bytes);
}
try (FileWriter fw = new FileWriter(className + ".asm"); PrintWriter pw = new PrintWriter(fw)) {
ClassReader cr = new ClassReader(bytes);
CheckClassAdapter.verify(cr, true, pw);
}
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Instrumented code saved to " + className + ".class and .asm");
} catch (IOException e) {
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Could not save instrumented code, for " + className + ".class and .asm");
}
}
}
示例3
public static void writeGeneratedASM(String className, byte[] bytes) {
if (SAVE_GENERATED == null) {
// We can't calculate value statically because it will force
// initialization of SecuritySupport, which cause
// UnsatisfiedLinkedError on JDK 8 or non-Oracle JDKs
SAVE_GENERATED = SecuritySupport.getBooleanProperty("jfr.save.generated.asm");
}
if (SAVE_GENERATED) {
try {
try (FileOutputStream fos = new FileOutputStream(className + ".class")) {
fos.write(bytes);
}
try (FileWriter fw = new FileWriter(className + ".asm"); PrintWriter pw = new PrintWriter(fw)) {
ClassReader cr = new ClassReader(bytes);
CheckClassAdapter.verify(cr, true, pw);
}
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Instrumented code saved to " + className + ".class and .asm");
} catch (IOException e) {
Logger.log(LogTag.JFR_SYSTEM_BYTECODE, LogLevel.INFO, "Could not save instrumented code, for " + className + ".class and .asm");
}
}
}
示例4
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例5
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInfoCollector.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例6
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例7
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例8
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例9
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例10
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInfoCollector.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例11
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInfoCollector.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例12
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInstrumentor.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例13
/**
* External entry point for ScriptClassInfoCollector if run from the command line
*
* @param args arguments - one argument is needed, the name of the class to collect info from
*
* @throws IOException if there are problems reading class
*/
public static void main(final String[] args) throws IOException {
if (args.length != 1) {
System.err.println("Usage: " + ScriptClassInfoCollector.class.getName() + " <class>");
System.exit(1);
}
final String fileName = args[0].replace('.', '/') + ".class";
final ScriptClassInfo sci = ClassGenerator.getScriptClassInfo(fileName);
if (sci == null) {
System.err.println("No @ScriptClass in " + fileName);
System.exit(2);
throw new AssertionError(); //guard against warning that sci is null below
}
try {
sci.verify();
} catch (final Exception e) {
System.err.println(e.getMessage());
System.exit(3);
}
final ClassWriter writer = ClassGenerator.makeClassWriter();
try (final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName))) {
final ClassReader reader = new ClassReader(bis);
final CheckClassAdapter checker = new CheckClassAdapter(writer);
final ScriptClassInstrumentor instr = new ScriptClassInstrumentor(checker, sci);
reader.accept(instr, 0);
}
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(writer.toByteArray());
}
}
示例14
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例15
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例16
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例17
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例18
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例19
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例20
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例21
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例22
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例23
private static void verify(final byte[] buf) {
final ClassReader cr = new ClassReader(buf);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
}
示例24
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), theStructLoader, false, new PrintWriter(System.err, true));
}
}
}
示例25
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), sharedLoader, false, new PrintWriter(System.err, true));
}
}
}
示例26
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), theStructLoader, false, new PrintWriter(System.err, true));
}
}
}
示例27
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), theStructLoader, false, new PrintWriter(System.err, true));
}
}
}
示例28
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), theStructLoader, false, new PrintWriter(System.err, true));
}
}
}
示例29
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), sharedLoader, false, new PrintWriter(System.err, true));
}
}
}
示例30
/**
* Verify generated bytecode before emission. This is called back from the
* {@link ObjectClassGenerator} or the {@link Compiler}. If the "--verify-code" parameter
* hasn't been given, this is a nop
*
* Note that verification may load classes -- we don't want to do that unless
* user specified verify option. We check it here even though caller
* may have already checked that flag
*
* @param bytecode bytecode to verify
*/
public void verify(final byte[] bytecode) {
if (env._verify_code) {
// No verification when security manager is around as verifier
// may load further classes - which should be avoided.
if (System.getSecurityManager() == null) {
CheckClassAdapter.verify(new ClassReader(bytecode), sharedLoader, false, new PrintWriter(System.err, true));
}
}
}