Is there a way to trigger JIT manually other than java.lang.Compiler
Asked Answered
N

1

7

I'm trying to build a JIT strategy based on method structure with profiling info (provided by JVM) but i didn't able to trigger JIT manually. This documentation says i can run JIT by invoking java.lang.Compiler.compileClass() but method returns false every time and the property that java.lang.Compiler checks (java.compiler) is null every time i run the JVM. I tried on OpenJDK and Oracle JVM 1.7 both results the same.

However when i observe the compilation statistics with

$ jstat -printcompilation <PID>

I can see the JIT successfully compiles some method which fits the conditions.

If any way exist I rather trigger it from java code. I tried to search in hotspot VM's code too but I couldn't locate the class and method where the decision made and JIT start.

Edit: After looking around more I found the compilationPolicy.cpp bu still couldn't find the exact location that the decision depend on. I would expect something like (simply thinking)

if(hot_count > Threshold){
   compile_method(methodHandle);
}

but instead found this,

void SimpleCompPolicy::method_invocation_event(methodHandle m, JavaThread* thread) {
const int comp_level = CompLevel_highest_tier;
  const int hot_count = m->invocation_count();
  reset_counter_for_invocation_event(m);
  const char* comment = "count";

  if (is_compilation_enabled() && can_be_compiled(m)) {
    nmethod* nm = m->code();
    if (nm == NULL ) {
    // [MY COMMENT] no check being done on hot_count in here or callee methods
      CompileBroker::compile_method(m, InvocationEntryBci, comp_level, m, hot_count, comment, thread);
    }
  }
}

As far as tracing the native JVM code, im getting away my main topic. Still looking for a simple solution to use in java side of the code.

Nobility answered 27/12, 2014 at 22:18 Comment(2)
Are you sure that you have the java.compiler property enabled on your machine? The documentation you referenced makes an explicit reference of that needing to be set. You can check with System.out.println(System.getProperty("java.compiler"));.Macrae
System.out.println(System.getProperty("java.compiler")); code prints null.And i am not sure i should set a value by myself even if should i cant find any documentation to set a specific value.Nobility
T
3

It sounds like you want something similar to the Compiler Control feature (http://openjdk.java.net/jeps/165).

Unfortunately, it doesn't exist yet, although it is currently scheduled to form part of Java 9.

Tedtedd answered 28/12, 2014 at 15:48 Comment(1)
Yes, i want something like that, to be more specific programmatic control. But i dont understand java.lang.Compiler class existence in the current JDK. If this class is a feature for different vendors to control JDK, why hotspot does not provide a default implementation to use 'Compiler'.Nobility

© 2022 - 2024 — McMap. All rights reserved.