bytecode

Strange exception table entry produced by Sun's javac

怎甘沉沦 提交于 2019-12-18 10:04:44
问题 Given this program: class Test { public static void main(String[] args) { try { throw new NullPointerException(); } catch (NullPointerException npe) { System.out.println("In catch"); } finally { System.out.println("In finally"); } } } Sun's javac (v 1.6.0_24) produces the following bytecode: public static void main(java.lang.String[]); // Instantiate / throw NPE 0: new #2; // class NullPointerException 3: dup 4: invokespecial #3; // Method NullPointerException."<init>":()V 7: athrow // Start

Find java class dependencies at runtime

送分小仙女□ 提交于 2019-12-18 09:22:27
问题 What's the most effective way to get a list of dependencies for a Java class at runtime? Using this (based on ASM ByteCode Manipulator 3.3.1), I can do the following: final Collection<Class<?>> classes = getClassesUsedBy(MyService.class.getName(), "com"); This returns references to BasicService and IService , but misses ContainerValue , and that's the issue. I played around with the ASM code but could not figure out how to pick up ContainerValue. package com.foo.bar; public class MyService

How would I go about parsing the Java class file constant pool?

血红的双手。 提交于 2019-12-18 07:10:53
问题 According to https://en.wikipedia.org/wiki/Java_class_file#General_layout - the Java constant pool of a class file begins 10 bytes into the file. So far, I've been able to parse everything before that (magic to check if it's a classfile, major/minor versions, constant pool size) but I still don't understand exactly how to parse the constant pool. Like, are there opcodes for specifying method refs and other things? Is there any way I can reference each hex value before text is represented in

Can compiled bytecode files (.pyc) get generated in different directory? [duplicate]

浪子不回头ぞ 提交于 2019-12-18 05:38:47
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Way to have compiled python files in a separate folder? When python compiles modules to bytecode, it produces .pyc files from your .py files. My question is, is it possible to have these .pyc files written to a different directory than where the module resides? For example, I have a large directory of modules. Rather than having it littered with .pyc files, I would like to keep my source code in the directory

Can compiled bytecode files (.pyc) get generated in different directory? [duplicate]

不问归期 提交于 2019-12-18 05:38:34
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Way to have compiled python files in a separate folder? When python compiles modules to bytecode, it produces .pyc files from your .py files. My question is, is it possible to have these .pyc files written to a different directory than where the module resides? For example, I have a large directory of modules. Rather than having it littered with .pyc files, I would like to keep my source code in the directory

What is the precedence of python compiled files in imports?

笑着哭i 提交于 2019-12-18 04:03:32
问题 Python files are compiled to bytecode (*.pyc). Using Cython you can compile them to machine code (*.so in Linux). If you use have both files in the same folder, under the same name what is the precedence between them? Is there an automatic way to ensure that the *.so file is used instead of the *.pyc one? Or you have to do it explicitly in the code (renaming etc)? 回答1: Python will load the .so file first. See this question for an ordered list of the suffixes that python searches for. Well, I

Default variables' values vs initialization with default

血红的双手。 提交于 2019-12-18 03:56:52
问题 We all know, that according to JLS7 p.4.12.5 every instance variable is initialized with default value. E.g. (1): public class Test { private Integer a; // == null private int b; // == 0 private boolean c; // == false } But I always thought, that such class implementation (2): public class Test { private Integer a = null; private int b = 0; private boolean c = false; } is absolutely equal to example (1). I expected, that sophisticated Java compiler see that all these initialization values in

Why does lambda translation need generation of a static method?

╄→尐↘猪︶ㄣ 提交于 2019-12-18 03:55:21
问题 Lambda translation is a two step process, One : desugaring the lambda into a static method in same class. public class Main { public static void main(String[] args) { Runnable r = () -> System.out.println("Hello"); System.out.println(Arrays.asList(Main.class.getDeclaredMethods())); } } [ private static void Main.lambda$main$0() , public static void Main.main(java.lang.String[])] Two : generation of a class that implements the Functional Interface. System.out.println("A class has been

Why switch on String compiles into two switches

跟風遠走 提交于 2019-12-18 03:05:29
问题 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:

What is the difference between assembly code and bytecode?

放肆的年华 提交于 2019-12-18 03:03:36
问题 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. 回答1: Assembly code normally does