< prev index next >

src/share/vm/compiler/compileBroker.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/dependencyContext.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "compiler/compilerOracle.hpp"
  34 #include "compiler/directivesParser.hpp"

  35 #include "interpreter/linkResolver.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "oops/methodData.hpp"
  38 #include "oops/method.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "prims/nativeLookup.hpp"
  41 #include "prims/whitebox.hpp"
  42 #include "runtime/arguments.hpp"
  43 #include "runtime/atomic.inline.hpp"
  44 #include "runtime/compilationPolicy.hpp"
  45 #include "runtime/init.hpp"
  46 #include "runtime/interfaceSupport.hpp"
  47 #include "runtime/javaCalls.hpp"
  48 #include "runtime/os.hpp"
  49 #include "runtime/sharedRuntime.hpp"
  50 #include "runtime/sweeper.hpp"
  51 #include "trace/tracing.hpp"
  52 #include "utilities/dtrace.hpp"
  53 #include "utilities/events.hpp"
  54 #ifdef COMPILER1


 887 
 888   // If this method is already in the compile queue, then
 889   // we do not block the current thread.
 890   if (compilation_is_in_queue(method)) {
 891     // We may want to decay our counter a bit here to prevent
 892     // multiple denied requests for compilation.  This is an
 893     // open compilation policy issue. Note: The other possibility,
 894     // in the case that this is a blocking compile request, is to have
 895     // all subsequent blocking requesters wait for completion of
 896     // ongoing compiles. Note that in this case we'll need a protocol
 897     // for freeing the associated compile tasks. [Or we could have
 898     // a single static monitor on which all these waiters sleep.]
 899     return;
 900   }
 901 
 902   // If the requesting thread is holding the pending list lock
 903   // then we just return. We can't risk blocking while holding
 904   // the pending list lock or a 3-way deadlock may occur
 905   // between the reference handler thread, a GC (instigated
 906   // by a compiler thread), and compiled method registration.
 907   if (InstanceRefKlass::owns_pending_list_lock(JavaThread::current())) {
 908     return;
 909   }
 910 
 911   if (TieredCompilation) {
 912     // Tiered policy requires MethodCounters to exist before adding a method to
 913     // the queue. Create if we don't have them yet.
 914     method->get_method_counters(thread);
 915   }
 916 
 917   // Outputs from the following MutexLocker block:
 918   CompileTask* task     = NULL;
 919   bool         blocking = false;
 920   CompileQueue* queue  = compile_queue(comp_level);
 921 
 922   // Acquire our lock.
 923   {
 924     MutexLocker locker(MethodCompileQueue_lock, thread);
 925 
 926     // Make sure the method has not slipped into the queues since
 927     // last we checked; note that those checks were "fast bail-outs".


1292   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1293   // only _compilation_id is incremented.
1294   return Atomic::add(1, &_compilation_id);
1295 #endif
1296 }
1297 
1298 // ------------------------------------------------------------------
1299 // CompileBroker::assign_compile_id_unlocked
1300 //
1301 // 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) {
1303   MutexLocker locker(MethodCompileQueue_lock, thread);
1304   return assign_compile_id(method, osr_bci);
1305 }
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 
1317 // ------------------------------------------------------------------
1318 // CompileBroker::preload_classes
1319 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
1320   // Move this code over from c1_Compiler.cpp
1321   ShouldNotReachHere();
1322 }
1323 
1324 
1325 // ------------------------------------------------------------------
1326 // CompileBroker::create_compile_task
1327 //
1328 // Create a CompileTask object representing the current request for
1329 // compilation.  Add this task to the queue.
1330 CompileTask* CompileBroker::create_compile_task(CompileQueue*       queue,
1331                                                 int                 compile_id,
1332                                                 const methodHandle& method,


   1 /*
   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.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/dependencyContext.hpp"
  31 #include "compiler/compileBroker.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "compiler/compilerOracle.hpp"
  34 #include "compiler/directivesParser.hpp"
  35 #include "gc/shared/referencePendingListLocker.hpp"
  36 #include "interpreter/linkResolver.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/nativeLookup.hpp"
  42 #include "prims/whitebox.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/atomic.inline.hpp"
  45 #include "runtime/compilationPolicy.hpp"
  46 #include "runtime/init.hpp"
  47 #include "runtime/interfaceSupport.hpp"
  48 #include "runtime/javaCalls.hpp"
  49 #include "runtime/os.hpp"
  50 #include "runtime/sharedRuntime.hpp"
  51 #include "runtime/sweeper.hpp"
  52 #include "trace/tracing.hpp"
  53 #include "utilities/dtrace.hpp"
  54 #include "utilities/events.hpp"
  55 #ifdef COMPILER1


 888 
 889   // If this method is already in the compile queue, then
 890   // we do not block the current thread.
 891   if (compilation_is_in_queue(method)) {
 892     // We may want to decay our counter a bit here to prevent
 893     // multiple denied requests for compilation.  This is an
 894     // open compilation policy issue. Note: The other possibility,
 895     // in the case that this is a blocking compile request, is to have
 896     // all subsequent blocking requesters wait for completion of
 897     // ongoing compiles. Note that in this case we'll need a protocol
 898     // for freeing the associated compile tasks. [Or we could have
 899     // a single static monitor on which all these waiters sleep.]
 900     return;
 901   }
 902 
 903   // If the requesting thread is holding the pending list lock
 904   // then we just return. We can't risk blocking while holding
 905   // the pending list lock or a 3-way deadlock may occur
 906   // between the reference handler thread, a GC (instigated
 907   // by a compiler thread), and compiled method registration.
 908   if (ReferencePendingListLocker::is_locked_by_self()) {
 909     return;
 910   }
 911 
 912   if (TieredCompilation) {
 913     // Tiered policy requires MethodCounters to exist before adding a method to
 914     // the queue. Create if we don't have them yet.
 915     method->get_method_counters(thread);
 916   }
 917 
 918   // Outputs from the following MutexLocker block:
 919   CompileTask* task     = NULL;
 920   bool         blocking = false;
 921   CompileQueue* queue  = compile_queue(comp_level);
 922 
 923   // Acquire our lock.
 924   {
 925     MutexLocker locker(MethodCompileQueue_lock, thread);
 926 
 927     // Make sure the method has not slipped into the queues since
 928     // last we checked; note that those checks were "fast bail-outs".


1293   // CICountOSR is a develop flag and set to 'false' by default. In a product built,
1294   // only _compilation_id is incremented.
1295   return Atomic::add(1, &_compilation_id);
1296 #endif
1297 }
1298 
1299 // ------------------------------------------------------------------
1300 // CompileBroker::assign_compile_id_unlocked
1301 //
1302 // Public wrapper for assign_compile_id that acquires the needed locks
1303 uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
1304   MutexLocker locker(MethodCompileQueue_lock, thread);
1305   return assign_compile_id(method, osr_bci);
1306 }
1307 
1308 /**
1309  * Should the current thread block until this compilation request
1310  * has been fulfilled?
1311  */
1312 bool CompileBroker::is_compile_blocking() {
1313   assert(!ReferencePendingListLocker::is_locked_by_self(), "possible deadlock");
1314   return !BackgroundCompilation;
1315 }
1316 
1317 
1318 // ------------------------------------------------------------------
1319 // CompileBroker::preload_classes
1320 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
1321   // Move this code over from c1_Compiler.cpp
1322   ShouldNotReachHere();
1323 }
1324 
1325 
1326 // ------------------------------------------------------------------
1327 // CompileBroker::create_compile_task
1328 //
1329 // Create a CompileTask object representing the current request for
1330 // compilation.  Add this task to the queue.
1331 CompileTask* CompileBroker::create_compile_task(CompileQueue*       queue,
1332                                                 int                 compile_id,
1333                                                 const methodHandle& method,


< prev index next >