hotspot/src/share/vm/compiler/compileBroker.cpp
changeset 36597 ee256e343585
parent 36322 218528915a61
child 36806 b9a6883c30ee
child 37179 4dbcb3a642d2
equal deleted inserted replaced
36595:3322a76f3a00 36597:ee256e343585
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   836                                         int osr_bci,
   836                                         int osr_bci,
   837                                         int comp_level,
   837                                         int comp_level,
   838                                         const methodHandle& hot_method,
   838                                         const methodHandle& hot_method,
   839                                         int hot_count,
   839                                         int hot_count,
   840                                         const char* comment,
   840                                         const char* comment,
       
   841                                         bool blocking,
   841                                         Thread* thread) {
   842                                         Thread* thread) {
   842   // do nothing if compiler thread(s) is not available
       
   843   if (!_initialized) {
       
   844     return;
       
   845   }
       
   846 
       
   847   guarantee(!method->is_abstract(), "cannot compile abstract methods");
   843   guarantee(!method->is_abstract(), "cannot compile abstract methods");
   848   assert(method->method_holder()->is_instance_klass(),
   844   assert(method->method_holder()->is_instance_klass(),
   849          "sanity check");
   845          "sanity check");
   850   assert(!method->method_holder()->is_not_initialized(),
   846   assert(!method->method_holder()->is_not_initialized(),
   851          "method holder must be initialized");
   847          "method holder must be initialized");
   914     method->get_method_counters(thread);
   910     method->get_method_counters(thread);
   915   }
   911   }
   916 
   912 
   917   // Outputs from the following MutexLocker block:
   913   // Outputs from the following MutexLocker block:
   918   CompileTask* task     = NULL;
   914   CompileTask* task     = NULL;
   919   bool         blocking = false;
       
   920   CompileQueue* queue  = compile_queue(comp_level);
   915   CompileQueue* queue  = compile_queue(comp_level);
   921 
   916 
   922   // Acquire our lock.
   917   // Acquire our lock.
   923   {
   918   {
   924     MutexLocker locker(MethodCompileQueue_lock, thread);
   919     MutexLocker locker(MethodCompileQueue_lock, thread);
   943     int compile_id = assign_compile_id(method, osr_bci);
   938     int compile_id = assign_compile_id(method, osr_bci);
   944     if (compile_id == 0) {
   939     if (compile_id == 0) {
   945       // The compilation falls outside the allowed range.
   940       // The compilation falls outside the allowed range.
   946       return;
   941       return;
   947     }
   942     }
   948 
       
   949     // Should this thread wait for completion of the compile?
       
   950     blocking = is_compile_blocking();
       
   951 
   943 
   952 #if INCLUDE_JVMCI
   944 #if INCLUDE_JVMCI
   953     if (UseJVMCICompiler) {
   945     if (UseJVMCICompiler) {
   954       if (blocking) {
   946       if (blocking) {
   955         // Don't allow blocking compiles for requests triggered by JVMCI.
   947         // Don't allow blocking compiles for requests triggered by JVMCI.
  1032   if (blocking) {
  1024   if (blocking) {
  1033     wait_for_completion(task);
  1025     wait_for_completion(task);
  1034   }
  1026   }
  1035 }
  1027 }
  1036 
  1028 
  1037 
       
  1038 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
  1029 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
  1039                                        int comp_level,
  1030                                        int comp_level,
  1040                                        const methodHandle& hot_method, int hot_count,
  1031                                        const methodHandle& hot_method, int hot_count,
  1041                                        const char* comment, Thread* THREAD) {
  1032                                        const char* comment, Thread* THREAD) {
       
  1033   // do nothing if compilebroker is not available
       
  1034   if (!_initialized) {
       
  1035     return NULL;
       
  1036   }
       
  1037   AbstractCompiler *comp = CompileBroker::compiler(comp_level);
       
  1038   assert(comp != NULL, "Ensure we don't compile before compilebroker init");
       
  1039   DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
       
  1040   nmethod* nm = CompileBroker::compile_method(method, osr_bci, comp_level, hot_method, hot_count, comment, directive, THREAD);
       
  1041   DirectivesStack::release(directive);
       
  1042   return nm;
       
  1043 }
       
  1044 
       
  1045 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
       
  1046                                          int comp_level,
       
  1047                                          const methodHandle& hot_method, int hot_count,
       
  1048                                          const char* comment, DirectiveSet* directive,
       
  1049                                          Thread* THREAD) {
       
  1050 
  1042   // make sure arguments make sense
  1051   // make sure arguments make sense
  1043   assert(method->method_holder()->is_instance_klass(), "not an instance method");
  1052   assert(method->method_holder()->is_instance_klass(), "not an instance method");
  1044   assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1053   assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
  1045   assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
  1054   assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
  1046   assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
  1055   assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
  1049   // return quickly if possible
  1058   // return quickly if possible
  1050 
  1059 
  1051   // lock, make sure that the compilation
  1060   // lock, make sure that the compilation
  1052   // isn't prohibited in a straightforward way.
  1061   // isn't prohibited in a straightforward way.
  1053   AbstractCompiler *comp = CompileBroker::compiler(comp_level);
  1062   AbstractCompiler *comp = CompileBroker::compiler(comp_level);
  1054   if (comp == NULL || !comp->can_compile_method(method) ||
  1063   if (!comp->can_compile_method(method) ||
  1055       compilation_is_prohibited(method, osr_bci, comp_level)) {
  1064       compilation_is_prohibited(method, osr_bci, comp_level, directive->ExcludeOption)) {
  1056     return NULL;
  1065     return NULL;
  1057   }
  1066   }
  1058 
  1067 
  1059   if (osr_bci == InvocationEntryBci) {
  1068   if (osr_bci == InvocationEntryBci) {
  1060     // standard compilation
  1069     // standard compilation
  1158     // fail out now so blocking compiles dont hang the java thread
  1167     // fail out now so blocking compiles dont hang the java thread
  1159     if (!should_compile_new_jobs()) {
  1168     if (!should_compile_new_jobs()) {
  1160       CompilationPolicy::policy()->delay_compilation(method());
  1169       CompilationPolicy::policy()->delay_compilation(method());
  1161       return NULL;
  1170       return NULL;
  1162     }
  1171     }
  1163     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD);
  1172     compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, !directive->BackgroundCompilationOption, THREAD);
  1164   }
  1173   }
  1165 
  1174 
  1166   // return requested nmethod
  1175   // return requested nmethod
  1167   // We accept a higher level osr method
  1176   // We accept a higher level osr method
  1168   if (osr_bci == InvocationEntryBci) {
  1177   if (osr_bci == InvocationEntryBci) {
  1215 
  1224 
  1216 // ------------------------------------------------------------------
  1225 // ------------------------------------------------------------------
  1217 // CompileBroker::compilation_is_prohibited
  1226 // CompileBroker::compilation_is_prohibited
  1218 //
  1227 //
  1219 // See if this compilation is not allowed.
  1228 // See if this compilation is not allowed.
  1220 bool CompileBroker::compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level) {
  1229 bool CompileBroker::compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded) {
  1221   bool is_native = method->is_native();
  1230   bool is_native = method->is_native();
  1222   // Some compilers may not support the compilation of natives.
  1231   // Some compilers may not support the compilation of natives.
  1223   AbstractCompiler *comp = compiler(comp_level);
  1232   AbstractCompiler *comp = compiler(comp_level);
  1224   if (is_native &&
  1233   if (is_native &&
  1225       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
  1234       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
  1232   if (is_osr &&
  1241   if (is_osr &&
  1233       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
  1242       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
  1234     method->set_not_osr_compilable(comp_level);
  1243     method->set_not_osr_compilable(comp_level);
  1235     return true;
  1244     return true;
  1236   }
  1245   }
  1237 
       
  1238   // Breaking the abstraction - directives are only used inside a compilation otherwise.
       
  1239   DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
       
  1240   bool excluded = directive->ExcludeOption;
       
  1241   DirectivesStack::release(directive);
       
  1242 
  1246 
  1243   // The method may be explicitly excluded by the user.
  1247   // The method may be explicitly excluded by the user.
  1244   double scale;
  1248   double scale;
  1245   if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
  1249   if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
  1246     bool quietly = CompilerOracle::should_exclude_quietly();
  1250     bool quietly = CompilerOracle::should_exclude_quietly();
  1301 // Public wrapper for assign_compile_id that acquires the needed locks
  1305 // Public wrapper for assign_compile_id that acquires the needed locks
  1302 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
  1306 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
  1303   MutexLocker locker(MethodCompileQueue_lock, thread);
  1307   MutexLocker locker(MethodCompileQueue_lock, thread);
  1304   return assign_compile_id(method, osr_bci);
  1308   return assign_compile_id(method, osr_bci);
  1305 }
  1309 }
  1306 
       
  1307 /**
       
  1308  * Should the current thread block until this compilation request
       
  1309  * has been fulfilled?
       
  1310  */
       
  1311 bool CompileBroker::is_compile_blocking() {
       
  1312   assert(!InstanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
       
  1313   return !BackgroundCompilation;
       
  1314 }
       
  1315 
       
  1316 
  1310 
  1317 // ------------------------------------------------------------------
  1311 // ------------------------------------------------------------------
  1318 // CompileBroker::preload_classes
  1312 // CompileBroker::preload_classes
  1319 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
  1313 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
  1320   // Move this code over from c1_Compiler.cpp
  1314   // Move this code over from c1_Compiler.cpp