jit

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

半腔热情 提交于 2019-11-28 13:06:58
问题 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,

JIT in JCuda, loading multiple ptx modules

依然范特西╮ 提交于 2019-11-28 12:40:05
I said in this question that I had some problem loading ptx modules in JCuda and after @talonmies's idea, I implemented a JCuda version of his solution to load multiple ptx files and load them as a single module. Here is the related part of the code: import static jcuda.driver.JCudaDriver.cuLinkAddFile; import static jcuda.driver.JCudaDriver.cuLinkComplete; import static jcuda.driver.JCudaDriver.cuLinkCreate; import static jcuda.driver.JCudaDriver.cuLinkDestroy; import static jcuda.driver.JCudaDriver.cuModuleGetFunction; import static jcuda.driver.JCudaDriver.cuModuleLoadData; import jcuda

How to alloc a executable memory buffer?

风格不统一 提交于 2019-11-28 11:38:17
I would like to alloc a buffer that I can execute on Win32 but I have an exception in visual studio cuz the malloc function returns a non executable memory zone. I read that there a NX flag to disable... My goal is convert a bytecode to asm x86 on fly with keep in mind performance. Does somemone can help me? JS You don't use malloc for that. Why would you anyway, in a C++ program? You also don't use new for executable memory, however. There's the Windows-specific VirtualAlloc function to reserve memory which you then mark as executable with the VirtualProtect function applying, for instance,

Disable Java JIT for a specific method/class?

久未见 提交于 2019-11-28 11:12:37
I'm having an issue in my Java application where the JIT breaks the code. If I disable the JIT, everything works fine, but runs 10-20x slower. Is there any way to disable the JIT for a specific method or class? Edit: I'm using Ubuntu 10.10, getting the same results both with: OpenJDK Runtime Environment (IcedTea6 1.9) (6b20-1.9-0ubuntu1) OpenJDK 64-Bit Server VM (build 17.0-b16, mixed mode) and: Java(TM) SE Runtime Environment (build 1.6.0_16-b01) Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode) The following option works on my JVMs, to exclude a specific method: -X

Do JVMs on Desktops Use JIT Compilation?

℡╲_俬逩灬. 提交于 2019-11-28 09:31:45
I always come across articles which claim that Java is interpreted. I know that Oracle's HotSpot JRE provides just-in-time compilation, however is this the case for a majority of desktop users? For example, if I download Java via: http://www.java.com/en/download , will this include a JIT Compiler? Yes, absolutely. Articles claiming Java is interpreted are typically written by people who either don't understand how Java works or don't understand what interpreted means. Having said that, HotSpot will interpret code sometimes - and that's a good thing. There are definitely portions of any

Is there any instruction reordering done by the Hotspot JIT compiler that can be reproduced?

别说谁变了你拦得住时间么 提交于 2019-11-28 09:06:54
As we know, some JIT allows reordering for object initialization, for example, someRef = new SomeObject(); can be decomposed into below steps: objRef = allocate space for SomeObject; //step1 call constructor of SomeObject; //step2 someRef = objRef; //step3 JIT compiler may reorder it as below: objRef = allocate space for SomeObject; //step1 someRef = objRef; //step3 call constructor of SomeObject; //step2 namely, step2 and step3 can be reordered by JIT compiler. Even though this is theoretically valid reordering, I was unable to reproduce it with Hotspot(jdk1.7) under x86 platform. So, Is

Angular 2 AOT vs JIT

时光毁灭记忆、已成空白 提交于 2019-11-28 09:02:35
问题 I was just reading Angular 2 AOT documentation and a few questions poped up The documentation clearly favours AOT over JIT and mentioned all the good stuff about how AOT is better. If that is the case why wouldn't AOT be the default build rather than doing ng build --prod --aot The documentation goes through in detail about how to set it up. Would ng build --prod --aot be good enough to ignore all those setup? 回答1: The documentation clearly favours AOT over JIT and mentioned all the good

Code sample that shows casting to uint is more efficient than range check

吃可爱长大的小学妹 提交于 2019-11-28 07:32:49
问题 So I am looking at this question and the general consensus is that uint cast version is more efficient than range check with 0. Since the code is also in MS's implementation of List I assume it is a real optimization. However I have failed to produce a code sample that results in better performance for the uint version. I have tried different tests and there is something missing or some other part of my code is dwarfing the time for the checks. My last attempt looks like this: class TestType

Why does Math.sin() delegate to StrictMath.sin()?

空扰寡人 提交于 2019-11-28 07:18:32
问题 I was wondering, why does Math.sin(double) delegate to StrictMath.sin(double) when I've found the problem in a Reddit thread. The mentioned code fragment looks like this (JDK 7u25): Math.java : public static double sin(double a) { return StrictMath.sin(a); // default impl. delegates to StrictMath } StrictMath.java : public static native double sin(double a); The second declaration is native which is reasonable for me. The doc of Math states that: Code generators are encouraged to use platform

Is there a runtime benefit to using const local variables?

谁都会走 提交于 2019-11-28 07:09:28
Outside of the ensuring that they cannot be changed (to the tune of a compiler error), does the JIT make any optimisations for const locals? Eg. public static int Main(string[] args) { const int timesToLoop = 50; for (int i=0; i<timesToLoop; i++) { // ... } } The generated IL is different (using Release mode): using constant local using normal local --------------------------------------------------------------------- .entrypoint .entrypoint .maxstack 2 .maxstack 2 .locals init ( .locals init ( [0] int32 i) [0] int32 timesToLoop, L_0000: ldc.i4.0 [1] int32 i) L_0001: stloc.0 L_0000: ldc.i4.s