hotspot/src/share/vm/runtime/compilationPolicy.cpp
changeset 46727 6e4a84748e2c
parent 43455 96560cffef4d
child 46729 c62d2e8b2728
equal deleted inserted replaced
46726:7801367e3cc9 46727:6e4a84748e2c
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2017, 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.
    94 }
    94 }
    95 
    95 
    96 // Returns true if m must be compiled before executing it
    96 // Returns true if m must be compiled before executing it
    97 // This is intended to force compiles for methods (usually for
    97 // This is intended to force compiles for methods (usually for
    98 // debugging) that would otherwise be interpreted for some reason.
    98 // debugging) that would otherwise be interpreted for some reason.
    99 bool CompilationPolicy::must_be_compiled(methodHandle m, int comp_level) {
    99 bool CompilationPolicy::must_be_compiled(const methodHandle& m, int comp_level) {
   100   // Don't allow Xcomp to cause compiles in replay mode
   100   // Don't allow Xcomp to cause compiles in replay mode
   101   if (ReplayCompiles) return false;
   101   if (ReplayCompiles) return false;
   102 
   102 
   103   if (m->has_compiled_code()) return false;       // already compiled
   103   if (m->has_compiled_code()) return false;       // already compiled
   104   if (!can_be_compiled(m, comp_level)) return false;
   104   if (!can_be_compiled(m, comp_level)) return false;
   105 
   105 
   106   return !UseInterpreter ||                                              // must compile all methods
   106   return !UseInterpreter ||                                              // must compile all methods
   107          (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods
   107          (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods
   108 }
   108 }
   109 
   109 
   110 void CompilationPolicy::compile_if_required(methodHandle selected_method, TRAPS) {
   110 void CompilationPolicy::compile_if_required(const methodHandle& selected_method, TRAPS) {
   111   if (must_be_compiled(selected_method)) {
   111   if (must_be_compiled(selected_method)) {
   112     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
   112     // This path is unusual, mostly used by the '-Xcomp' stress test mode.
   113 
   113 
   114     // Note: with several active threads, the must_be_compiled may be true
   114     // Note: with several active threads, the must_be_compiled may be true
   115     //       while can_be_compiled is false; remove assert
   115     //       while can_be_compiled is false; remove assert
   133         methodHandle(), 0, CompileTask::Reason_MustBeCompiled, CHECK);
   133         methodHandle(), 0, CompileTask::Reason_MustBeCompiled, CHECK);
   134   }
   134   }
   135 }
   135 }
   136 
   136 
   137 // Returns true if m is allowed to be compiled
   137 // Returns true if m is allowed to be compiled
   138 bool CompilationPolicy::can_be_compiled(methodHandle m, int comp_level) {
   138 bool CompilationPolicy::can_be_compiled(const methodHandle& m, int comp_level) {
   139   // allow any levels for WhiteBox
   139   // allow any levels for WhiteBox
   140   assert(WhiteBoxAPI || comp_level == CompLevel_all || is_compile(comp_level), "illegal compilation level");
   140   assert(WhiteBoxAPI || comp_level == CompLevel_all || is_compile(comp_level), "illegal compilation level");
   141 
   141 
   142   if (m->is_abstract()) return false;
   142   if (m->is_abstract()) return false;
   143   if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false;
   143   if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false;
   164   }
   164   }
   165   return false;
   165   return false;
   166 }
   166 }
   167 
   167 
   168 // Returns true if m is allowed to be osr compiled
   168 // Returns true if m is allowed to be osr compiled
   169 bool CompilationPolicy::can_be_osr_compiled(methodHandle m, int comp_level) {
   169 bool CompilationPolicy::can_be_osr_compiled(const methodHandle& m, int comp_level) {
   170   bool result = false;
   170   bool result = false;
   171   if (comp_level == CompLevel_all) {
   171   if (comp_level == CompLevel_all) {
   172     if (TieredCompilation) {
   172     if (TieredCompilation) {
   173       // enough to be osr compilable at any level for tiered
   173       // enough to be osr compilable at any level for tiered
   174       result = !m->is_not_osr_compilable(CompLevel_simple) || !m->is_not_osr_compilable(CompLevel_full_optimization);
   174       result = !m->is_not_osr_compilable(CompLevel_simple) || !m->is_not_osr_compilable(CompLevel_full_optimization);