bytecode

Keeping everything in a single lua bytecode chunk?

北慕城南 提交于 2019-11-30 03:59:31
I've embedded lua together with a bytecode chunk into a project written in C. Now when I extend my lua code base by adding .lua files, is there a way to keep this code in a single bytecode chunk? (I know how to load multiple bytecode chunks. But making it load a single chunk and then forgetting about the glue code would just seem comfortable.) I tried to use textual inclusion, but it seems there's no keyword for this in Lua. "Require" and "dofile" look at the files at run time, so the resulting bytecode after running "lua -b ..." won't include the code of those files. And there's no way for

Given a python .pyc file, is there a tool that let me view the bytecode?

試著忘記壹切 提交于 2019-11-30 02:25:45
A Python module is automatically compiled into a .pyc file by CPython interpreter. The .pyc file, which contains the bytecode, is in binary format (marshaled code?). Is there a GUI (or command line) tool that let me view the bytecode? There's a visual python disassembler called PyChrisanthemum . To do it the command-line way you can use module dis ( python 2.7.3 , python 3.2.3 ), as OP already found out. Seti Volkylany Every *.pyc file is a binary file containing next things: a four-byte magic number - it's simply bytes that change with each change to the marshalling code; a four-byte

How to generate a module object from a code object in Python

冷暖自知 提交于 2019-11-30 02:08:58
Given that I have the code object for a module, how do I get the corresponding module object? It looks like moduleNames = {}; exec code in moduleNames does something very close to what I want. It returns the globals declared in the module into a dictionary. But if I want the actual module object, how do I get it? EDIT: It looks like you can roll your own module object. The module type isn't conveniently documented, but you can do something like this: import sys module = sys.__class__ del sys foo = module('foo', 'Doc string') foo.__file__ = 'foo.pyc' exec code in foo.__dict__ As a comment

Which library/program can be used to generate Java-bytecode? [closed]

白昼怎懂夜的黑 提交于 2019-11-30 01:16:11
I know about BCEL , but this project seems to be dead, as it had no releases for two years. And the Java-world moves on. For example JDK 1.6 has a new class-file-format. So what library can be used to create bytecode for the JVM. If no library, a program is ok too, if I can manipulate the generated code in detail, for example a bytecode-assembler. Which software can you recommend? Is it easy too use? has good examples/tutorials? EDIT: For all asking: Yes, the javac is fine. But for generating some classes at runtime, a path directly to bytecode would be cleaner. ASM http://asm.objectweb.org/

does Java type erasure erase my generic type?

北战南征 提交于 2019-11-30 00:39:05
I've thought java erasure wipes generic types out in compile time however when i test it by myself i realized there are some information about generic types in Bytecode. here is my test : i wrote 2 classes: import java.util.*; public class Test { List integerList; } and import java.util.*; public class Test { List<Integer> integerList; } i compiled both classes and somewhere in generic class i saw this line integerList{blah blah}Ljava/util/List;{blah blah} Signature{blah blah}%Ljava/util/List<Ljava/lang/Integer;>;{blah blah}<init> in non generic class : integerList{blah blah}Ljava/util/List;

where are the .pyc files?

南笙酒味 提交于 2019-11-30 00:32:00
问题 I am a complete newb to python, hence a silly question. As i understand, upon first execution of a *.py program, byte code is created into *.pyc and used until a change in *.py file. Where might this *.pyc bytecode be found in a project? I would think bin, but nothing is there 回答1: A *.pyc file is created for imported modules, and they are placed in the same directory containing the .py file. However... no .pyc file is created for the main script for your program. In other words... if you

How can you extend Java to introduce passing by reference?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 00:00:39
Java is pass-by-value. How could you modify the language to introduce passing by reference (or some equivalent behavior)? Take for example something like public static void main(String[] args) { String variable = "'previous String reference'"; passByReference(ref variable); System.out.println(variable); // I want this to print 'new String reference' } public static void passByReference(ref String someString) { someString = "'new String reference'"; } which (without the ref ) compiles to the following bytecode public static void main(java.lang.String[]); Code: 0: ldc #2 // String 'previous

Is it possible to have the System ClassLoader load .class files specified at run time?

雨燕双飞 提交于 2019-11-29 21:16:39
问题 I am writing a static analysis tool for an assignment, it analyses Java bytecode using the ASM library. One of the parts of ASM that we use requires (or at least, appears to require) that the class be loaded from the ClassLoader. We were hoping the tool would be able to analyse .class files without requiring them on the classpath. We already load the .classes from a specified directory at run time and read them in using an InputStream. This is acceptable for ASM in most cases. There are some

Why is 2 * (i * i) faster than 2 * i * i in Java?

一曲冷凌霜 提交于 2019-11-29 18:30:48
The following Java program takes on average between 0.50 secs and 0.55 secs to run: public static void main(String[] args) { long startTime = System.nanoTime(); int n = 0; for (int i = 0; i < 1000000000; i++) { n += 2 * (i * i); } System.out.println((double) (System.nanoTime() - startTime) / 1000000000 + " s"); System.out.println("n = " + n); } If I replace 2 * (i * i) with 2 * i * i , it takes between 0.60 and 0.65 secs to run. How come? I ran each version of the program 15 times, alternating between the two. Here are the results: 2*(i*i) | 2*i*i ----------+---------- 0.5183738 | 0.6246434 0

Find java class dependencies at runtime

穿精又带淫゛_ 提交于 2019-11-29 16:43:54
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 extends BasicService implements IService { public String invoke(){ return new ContainerValue("bar")