jit

How to compile a C code during execution time, and get a pointer to the corresponding function?

≡放荡痞女 提交于 2019-12-04 22:05:52
Suppose I generate a C program during execution time: source = "int add_x_y(int x, int y){ return x + y; }"; source_size = 42; I want the following function: void* compile(char* source, int source_size); Such that: int (*f)(int,int) = compile(source, source_size); printf("%d\n",f(2,3)); Outputs: 5 And compile can't depend on external tools (compilers), as I'd like to use it in emscripten (which converts a C program to a .js file). Is that possible? Someone else can probably fill in some of the specifics better than I, but if you don't mind calling out to GCC or linking to it, it should be

convert JIT to EXE?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:35:39
Since so there are so many JIT implementation out there, every JIT emits native code. Then why hasn't someone made a tool like JIT2EXE, to save the native code to a native executable? The question is kind of vague as you have not clearly specified what language you are talking about, in my area of .NET, the .NET executables are pre-jitted at runtime in order to speed up the loading times. The code can be generated to native code by a process known as NGEN which takes the .NET IL code and converts it in the process of a binary in which can be understood by the processor. Usually NGEN code are

What are the differences in JIT between Java and .Net

早过忘川 提交于 2019-12-04 16:48:36
问题 I know Microsoft .NET uses the CLR as a JIT compiler while Java has the Hotspot. What Are the differences between them? 回答1: They are very different beasts. As people pointed out, the CLR compiles to machine code before it executes a piece of MSIL. This allows it in addition to the typical dead-code elimination and inlining off privates optimizations to take advantage of the particular CPU architecture of the target machine (though I'm not sure whether it does it). This also incurs a hit for

How JIT Compilers Operate

孤人 提交于 2019-12-04 14:37:39
JIT compilers, by definition, generate code on the fly for execution. But in, say, Windows, we have all kinds of protection that prevent self modifying code or executing from data memory (DEP). So how is it possible for JIT compilers to generate code on the fly? They ask the OS for some memory which is readable, writeable and executable. e.g. you can allocate such memory using mmap() with PROT_READ | PROT_WRITE | PROT_EXEC (POSIX), or VirtualAlloc() with PAGE_EXECUTE_READWRITE (Windows). For a real example, see LLVM's llvm::sys::Memory::AllocateRWX ( Unix implementation ; Windows

Reason and tracing of class loading during verification, method execution and JIT compilation

拥有回忆 提交于 2019-12-04 14:21:53
问题 I'm trying to understand which events lead to class loads on a very detailed basis and during my testing encountered one behaviour I do not understand in this very basic sample: public class ClinitTest { public static Integer num; public static Long NUMTEST; static { NUMTEST = new Long(15);; num = (int) (NUMTEST * 5); System.out.println(num); } public static void main(String[] args) { System.out.println( "The number is " + num); } } When running java.lang.Long gets loaded while executing the

High, Fluctuating '% Time in JIT' on Precompiled ASP.NET Website

痴心易碎 提交于 2019-12-04 14:18:44
问题 With a 150 *.dll ASP.NET website that's precompiled (updatable), what are some possible causes for a ' % Time in JIT ' that is often quite high (> 60%) and fluctuating long after the application has warmed-up (all functionality accessed) and without app restarts or file changes that might generate new assemblies? One would expect that the machine code generated for all assemblies would be re-used for the duration of that app-domain. Is there a finite size to the volume of machine-code that's

C# based Windows Service - Tries to do JIT Debugging in production

坚强是说给别人听的谎言 提交于 2019-12-04 14:09:46
I am getting this error in my event logs for a service I put into production: An unhandled win32 exception occurred in RivWorks.FeedHandler.exe [5496]. Just-In-Time debugging this exception failed with the following error: Debugger could not be started because no user is logged on. I have it installed and running under a Win NT global account. I have no idea why it is trying to drop into debugging mode. It was built under the Release model. Running on the 4.0 Framework. When I run on my dev machine, via an EXE entry point instead of the WinSvc entry point, everything runs just fine - BUT - I

Generating functions at runtime in C

谁说胖子不能爱 提交于 2019-12-04 13:49:03
问题 I would like to generate a function at runtime in C. And by this I mean I would essentially like to allocate some memory, point at it and execute it via function pointer. I realize this is a very complex topic and my question is naïve. I also realize there are some very robust libraries out there that do this (e.g. nanojit). But I would like to learn the technique, starting with the basics. Could someone knowledgeable give me a very simple example in C? EDIT: The answer below is great but

Why after changing a static readonly field via reflection the output of that readonly field is old?

时间秒杀一切 提交于 2019-12-04 13:43:52
Why is the "someValue" variable which is readonly (but we still can change its value via reflection) output as "10", although it actually did change to 55? static class Program { static readonly int someValue = 10; static void Main(string[] args) { Console.WriteLine(someValue); // 10 typeof(Program) .GetField("someValue", BindingFlags.Static | BindingFlags.NonPublic) .SetValue(null, 55); // change readonly field via reflection to 55 Console.WriteLine(someValue); // output in console 10, // but in visual studio debugger it shows 55 Console.ReadKey(); } } Probably just a JIT optimization to

Play framework. no need to compile

会有一股神秘感。 提交于 2019-12-04 13:12:08
问题 I was introduced to the Play framework, and one of the amazing things I found about it is that there is no need to compile the project. You only need to save the edited files and reload the webpage. I've been taught that Java source code is compiled to bytecode and then compiled with the JIT compiler, so what is the magic inside of the Play framework? 回答1: When running in DEV mode, Play works by checking the last modified date of the java files, and cross referencing them with the .class