bytecode

running jython bytecode using java

心已入冬 提交于 2019-11-29 02:01:39
It looks like I'm missing something. When using Jython to run my Python code in Java, Java bytecode files are generated (test.py -> test@py.class). Can I run these classes directly using java? In other words, I want to make this: $ java test@py [additional cp args] work. The intent: writing Python code and not having to give away source code. Here's what works for me: test_p.py: def foo(): print 'test from Python' TestJ.java: import org.python.core.PyFrame; import org.python.core.PyFunctionTable; import org.python.util.PythonInterpreter; public class TestJ { public static void main(String[]

Why are JSR/RET deprecated Java bytecode?

有些话、适合烂在心里 提交于 2019-11-29 01:57:34
Does anyone know why the JSR/RET bytecode pair is deprecated in Java 6? The only meaningful explanation I found on the net was that they made code analysis by the runtime harder and slower to perform. Does anyone know another reason? Trent Gray-Donald JSR and RET make bytecode verification a lot more difficult than it might otherwise be due to the relaxation of some normal bytecode constraints (such as having a consistent stack shape on entry to a JSR). The upside is very minor (potentially slightly smaller methods in some cases) and the continuing difficulties in the verifier dealing with odd

Why python compile the source to bytecode before interpreting?

谁说胖子不能爱 提交于 2019-11-29 01:45:30
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly? Nearly no interpreter really interprets code directly , line by line – it's simply too inefficient. Almost all interpreters use some intermediate representation which can be executed easily. Also, small optimizations can be performed on this intermediate code. Python furthermore stores this code which has a huge advantage for the next time this code gets executed: Python doesn't have to parse the code anymore; parsing is the slowest part in the compile process. Thus, a bytecode

Is it possible to view a Java class files bytecode [duplicate]

眉间皱痕 提交于 2019-11-29 01:25:15
This question already has an answer here: Is it possible to view bytecode of Class file? [duplicate] 5 answers I am working on a bytecode manipulation/generation in Java and I was just wondering if there is an easy way I could check the bytecode. I do not want to decompile the file, I would like to actually look at the compiled bytecode. I do not need to edit it. Any links or programs for doing this would be acceptable answers. I've been working on a decompiler that has a color-coded bytecode output mode (which I find far more readable than javap). It can also output Java code or an

Why switch on String compiles into two switches

╄→尐↘猪︶ㄣ 提交于 2019-11-29 01:18:20
I read JVM specification on compiling switches and became interested in how switch statement on String is compiled. Here is the test method I examined (JDK1.7.0_40): static int test(String i) { switch (i) { case "a": return -100; case "45b": return 1; case "c": return 2; default: return -1; } } I expect this method to be compiled into simple lookupswitch on hashCode of string, but suddenly static int test(java.lang.String); Code: 0: aload_0 1: astore_1 2: iconst_m1 3: istore_2 4: aload_1 5: invokevirtual #6 // Method java/lang/String.hashCode:()I 8: lookupswitch { // 3 97: 44 99: 72 51713: 58

What is the difference between assembly code and bytecode?

和自甴很熟 提交于 2019-11-29 01:12:28
While in the search for the various differences in the meanings of source code, bytecode, assembly code, machine code, compilers, linkers, interpreters, assemblers and all the rest, I only got confused on the difference between bytcode and assembly code. Particularly the introduction this wikipedia article to describe CIL confused me since it seems to use both terms (assembly code and bytecode) interchangeably making me think they might mean exactly the same. Juergen Assembly code normally does mean the human readable form of a machine's native language (the so called machine language). Byte

Is it possible to inject code in an android application?

好久不见. 提交于 2019-11-29 00:28:23
I would like to inject code in an android application at runtime. I have tried to use dx tool to generate a dexfile in the sdcard but when i want to instantiate, it fails. Are there any tools to inject code generating new dalvik bytecode? I am studing some libraries, aspecjt or guice for android. Is it better to work with a script language? Thanks people :) No, it is not possible. Android application permissions would not work if that was possible. Dexmaker is new and designed just for this. Here's part of the example from the project website: DexMaker dexMaker = new DexMaker(); // Generate a

Java method parameters values in ASM

心不动则不痛 提交于 2019-11-28 23:49:52
I am trying to get the values of a Java program's method's parameters. I am using ASM to instrument the bytecode and getting these values. However, I'm running into some troubles. Here is the visitCode() method used to instrument the code. What it is doing is : Create an empty array to store the collected parameters. For each parameter, load its value into the array. Send this array to my agent's OnMethodEntry method (which where the values will be used). . @Override public void visitCode() { int paramLength = paramTypes.length; // Create array with length equal to number of parameters mv

Transforming lambdas in Java 8

ε祈祈猫儿з 提交于 2019-11-28 23:27:17
Java 8 appears to generate classes to represent lambda expressions. For instance, the code: Runnable r = app::doStuff; Manifests, roughly, as: // $FF: synthetic class final class App$$Lambda$1 implements Runnable { private final App arg$1; private App$$Lambda$1(App var1) { this.arg$1 = var1; } private static Runnable get$Lambda(App var0) { return new App$$Lambda$1(var0); } public void run() { this.arg$1.doStuff(); } } As I understand this, the code is generated at runtime. Now, suppose one wanted to inject code into the run method of the above class. Experiments thus far yield a mix of

How does bytecode get verified in the JVM?

限于喜欢 提交于 2019-11-28 23:25:52
How does bytecode get verified in the JVM? Oracle themselves have a little snippet page on how it works here . Basically, the JRE doesn't trust the JDK. That's because it has no knowledge of which JDK compiler created the class file. It treats the class file as hostile until verified. Expanding on that, the bytecode verification is a necessary step to protect from what Sun call a "hostile compiler". Sun's own Java compiler ensures that Java source code doesn't violate the safety rules but, when an application imports a code fragment, it doesn't actually know if the code fragment follows Java