/** * Disassemble an array of byte code. * @param bytecode byte array representing bytecode * @return disassembly as human readable string */ static String disassemble(final byte[] bytecode) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final PrintWriter pw = new PrintWriter(baos)) { final NashornClassReader cr = new NashornClassReader(bytecode); final Context ctx = AccessController.doPrivileged(new PrivilegedAction<Context>() { @Override public Context run() { return Context.getContext(); } }); final TraceClassVisitor tcv = new TraceClassVisitor(null, new NashornTextifier(ctx.getEnv(), cr), pw); cr.accept(tcv, 0); } final String str = new String(baos.toByteArray()); return str; }
/** * Disassemble an array of byte code. * * @param bytecode byte array representing bytecode * * @return disassembly as human readable string */ static String disassemble(final byte[] bytecode) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final PrintWriter pw = new PrintWriter(baos)) { final NashornClassReader cr = new NashornClassReader(bytecode); final Context ctx = AccessController.doPrivileged(new PrivilegedAction<Context>() { @Override public Context run() { return Context.getContext(); } }); final TraceClassVisitor tcv = new TraceClassVisitor(null, new NashornTextifier(ctx.getEnv(), cr), pw); cr.accept(tcv, 0); } final String str = new String(baos.toByteArray()); return str; }