hotspot/src/share/vm/runtime/simpleThresholdPolicy.cpp
author mgerdin
Thu, 23 Feb 2012 14:58:35 +0100
changeset 12095 cc3d6f08a4c4
parent 11572 84afef481892
child 13728 882756847a04
permissions -rw-r--r--
7148152: Add whitebox testing API to HotSpot Summary: Add an internal testing API to HotSpot to enable more targeted testing of vm functionality Reviewed-by: phh, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     1
/*
9625
822a93889b58 7043564: compile warning and copyright fixes
iveresov
parents: 8322
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     4
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     8
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    13
 * accompanied this code).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    14
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    18
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    21
 * questions.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    22
 *
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    23
 */
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    26
#include "compiler/compileBroker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    27
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    28
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    29
#include "runtime/simpleThresholdPolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7389
diff changeset
    30
#include "runtime/simpleThresholdPolicy.inline.hpp"
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    31
#include "code/scopeDesc.hpp"
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    32
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    33
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    34
void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) {
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    35
  int invocation_count = mh->invocation_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    36
  int backedge_count = mh->backedge_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    37
  methodDataHandle mdh = mh->method_data();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    38
  int mdo_invocations = 0, mdo_backedges = 0;
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    39
  int mdo_invocations_start = 0, mdo_backedges_start = 0;
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    40
  if (mdh() != NULL) {
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    41
    mdo_invocations = mdh->invocation_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    42
    mdo_backedges = mdh->backedge_count();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    43
    mdo_invocations_start = mdh->invocation_count_start();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    44
    mdo_backedges_start = mdh->backedge_count_start();
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    45
  }
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    46
  tty->print(" %stotal: %d,%d %smdo: %d(%d),%d(%d)", prefix,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    47
      invocation_count, backedge_count, prefix,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    48
      mdo_invocations, mdo_invocations_start,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    49
      mdo_backedges, mdo_backedges_start);
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    50
  tty->print(" %smax levels: %d,%d", prefix,
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    51
      mh->highest_comp_level(), mh->highest_osr_comp_level());
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    52
}
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
    53
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    54
// Print an event.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    55
void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    56
                                        int bci, CompLevel level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    57
  bool inlinee_event = mh() != imh();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    58
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    59
  ttyLocker tty_lock;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    60
  tty->print("%lf: [", os::elapsedTime());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    61
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    62
  switch(type) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    63
  case CALL:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    64
    tty->print("call");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    65
    break;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    66
  case LOOP:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    67
    tty->print("loop");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    68
    break;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    69
  case COMPILE:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    70
    tty->print("compile");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    71
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    72
  case REMOVE_FROM_QUEUE:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    73
    tty->print("remove-from-queue");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    74
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    75
  case UPDATE_IN_QUEUE:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    76
    tty->print("update-in-queue");
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    77
    break;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    78
  case REPROFILE:
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    79
    tty->print("reprofile");
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    80
    break;
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    81
  case MAKE_NOT_ENTRANT:
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    82
    tty->print("make-not-entrant");
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
    83
    break;
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    84
  default:
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
    85
    tty->print("unknown");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    86
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    87
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    88
  tty->print(" level: %d ", level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    89
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    90
  ResourceMark rm;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    91
  char *method_name = mh->name_and_sig_as_C_string();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    92
  tty->print("[%s", method_name);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    93
  if (inlinee_event) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    94
    char *inlinee_name = imh->name_and_sig_as_C_string();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    95
    tty->print(" [%s]] ", inlinee_name);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    96
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    97
  else tty->print("] ");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    98
  tty->print("@%d queues: %d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
    99
                                       CompileBroker::queue_size(CompLevel_full_optimization));
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   100
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   101
  print_specific(type, mh, imh, bci, level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   102
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   103
  if (type != COMPILE) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   104
    print_counters("", mh);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   105
    if (inlinee_event) {
11192
ff37c2093a0d 7112085: assert(fr.interpreter_frame_expression_stack_size()==0) failed: only handle empty stacks
iveresov
parents: 10250
diff changeset
   106
      print_counters("inlinee ", imh);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   107
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   108
    tty->print(" compilable: ");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   109
    bool need_comma = false;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   110
    if (!mh->is_not_compilable(CompLevel_full_profile)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   111
      tty->print("c1");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   112
      need_comma = true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   113
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   114
    if (!mh->is_not_compilable(CompLevel_full_optimization)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   115
      if (need_comma) tty->print(", ");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   116
      tty->print("c2");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   117
      need_comma = true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   118
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   119
    if (!mh->is_not_osr_compilable()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   120
      if (need_comma) tty->print(", ");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   121
      tty->print("osr");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   122
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   123
    tty->print(" status:");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   124
    if (mh->queued_for_compilation()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   125
      tty->print(" in queue");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   126
    } else tty->print(" idle");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   127
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   128
  tty->print_cr("]");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   129
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   130
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   131
void SimpleThresholdPolicy::initialize() {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   132
  if (FLAG_IS_DEFAULT(CICompilerCount)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   133
    FLAG_SET_DEFAULT(CICompilerCount, 3);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   134
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   135
  int count = CICompilerCount;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   136
  if (CICompilerCountPerCPU) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   137
    count = MAX2(log2_intptr(os::active_processor_count()), 1) * 3 / 2;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   138
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   139
  set_c1_count(MAX2(count / 3, 1));
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   140
  set_c2_count(MAX2(count - count / 3, 1));
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   141
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   142
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   143
void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   144
  if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   145
    counter->set_carry_flag();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   146
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   147
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   148
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   149
// Set carry flags on the counters if necessary
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   150
void SimpleThresholdPolicy::handle_counter_overflow(methodOop method) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   151
  set_carry_if_necessary(method->invocation_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   152
  set_carry_if_necessary(method->backedge_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   153
  methodDataOop mdo = method->method_data();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   154
  if (mdo != NULL) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   155
    set_carry_if_necessary(mdo->invocation_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   156
    set_carry_if_necessary(mdo->backedge_counter());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   157
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   158
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   159
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   160
// Called with the queue locked and with at least one element
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   161
CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   162
  return compile_queue->first();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   163
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   164
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   165
void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   166
  for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   167
    if (PrintTieredEvents) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   168
      methodHandle mh(sd->method());
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   169
      print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none);
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   170
    }
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   171
    methodDataOop mdo = sd->method()->method_data();
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   172
    if (mdo != NULL) {
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   173
      mdo->reset_start_counters();
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   174
    }
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   175
    if (sd->is_top()) break;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   176
  }
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   177
}
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   178
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   179
nmethod* SimpleThresholdPolicy::event(methodHandle method, methodHandle inlinee,
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   180
                                      int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   181
  if (comp_level == CompLevel_none &&
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   182
      JvmtiExport::can_post_interpreter_events() &&
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   183
      thread->is_interp_only_mode()) {
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   184
    return NULL;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   185
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   186
  nmethod *osr_nm = NULL;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   187
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   188
  handle_counter_overflow(method());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   189
  if (method() != inlinee()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   190
    handle_counter_overflow(inlinee());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   191
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   192
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   193
  if (PrintTieredEvents) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   194
    print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   195
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   196
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   197
  if (bci == InvocationEntryBci) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   198
    method_invocation_event(method, inlinee, comp_level, nm, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   199
  } else {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   200
    method_back_branch_event(method, inlinee, bci, comp_level, nm, thread);
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   201
    // method == inlinee if the event originated in the main method
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   202
    int highest_level = inlinee->highest_osr_comp_level();
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   203
    if (highest_level > comp_level) {
10014
a5c2141ee857 7057120: Tiered: Allow C1 to inline methods with loops
iveresov
parents: 10013
diff changeset
   204
      osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   205
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   206
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   207
  return osr_nm;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   208
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   209
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   210
// Check if the method can be compiled, change level if necessary
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   211
void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   212
  assert(level <= TieredStopAtLevel, "Invalid compilation level");
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   213
  if (level == CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   214
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   215
  }
7389
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   216
  // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   217
  // in the interpreter and then compile with C2 (the transition function will request that,
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   218
  // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
93110864f81e 7000349: Tiered reacts incorrectly to C1 compilation failures
iveresov
parents: 6453
diff changeset
   219
  // pure C1.
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   220
  if (!can_be_compiled(mh, level)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   221
    if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   222
        compile(mh, bci, CompLevel_simple, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   223
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   224
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   225
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   226
  if (bci != InvocationEntryBci && mh->is_not_osr_compilable()) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   227
    return;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   228
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   229
  if (!CompileBroker::compilation_is_in_queue(mh, bci)) {
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   230
    if (PrintTieredEvents) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   231
      print_event(COMPILE, mh, mh, bci, level);
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   232
    }
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   233
    submit_compile(mh, bci, level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   234
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   235
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   236
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   237
// Tell the broker to compile the method
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   238
void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   239
  int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   240
  CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   241
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   242
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   243
// Call and loop predicates determine whether a transition to a higher
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   244
// compilation level should be performed (pointers to predicate functions
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   245
// are passed to common() transition function).
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   246
bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   247
  switch(cur_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   248
  case CompLevel_none:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   249
  case CompLevel_limited_profile: {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   250
    return loop_predicate_helper<CompLevel_none>(i, b, 1.0);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   251
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   252
  case CompLevel_full_profile: {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   253
    return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   254
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   255
  default:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   256
    return true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   257
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   258
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   259
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   260
bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   261
  switch(cur_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   262
  case CompLevel_none:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   263
  case CompLevel_limited_profile: {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   264
    return call_predicate_helper<CompLevel_none>(i, b, 1.0);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   265
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   266
  case CompLevel_full_profile: {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   267
    return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   268
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   269
  default:
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   270
    return true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   271
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   272
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   273
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   274
// Determine is a method is mature.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   275
bool SimpleThresholdPolicy::is_mature(methodOop method) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   276
  if (is_trivial(method)) return true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   277
  methodDataOop mdo = method->method_data();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   278
  if (mdo != NULL) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   279
    int i = mdo->invocation_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   280
    int b = mdo->backedge_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   281
    double k = ProfileMaturityPercentage / 100.0;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   282
    return call_predicate_helper<CompLevel_full_profile>(i, b, k) ||
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   283
           loop_predicate_helper<CompLevel_full_profile>(i, b, k);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   284
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   285
  return false;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   286
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   287
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   288
// Common transition function. Given a predicate determines if a method should transition to another level.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   289
CompLevel SimpleThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   290
  CompLevel next_level = cur_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   291
  int i = method->invocation_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   292
  int b = method->backedge_count();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   293
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   294
  if (is_trivial(method)) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   295
    next_level = CompLevel_simple;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   296
  } else {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   297
    switch(cur_level) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   298
    case CompLevel_none:
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   299
      // If we were at full profile level, would we switch to full opt?
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   300
      if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   301
        next_level = CompLevel_full_optimization;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   302
      } else if ((this->*p)(i, b, cur_level)) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   303
        next_level = CompLevel_full_profile;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   304
      }
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   305
      break;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   306
    case CompLevel_limited_profile:
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   307
    case CompLevel_full_profile:
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   308
      {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   309
        methodDataOop mdo = method->method_data();
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   310
        if (mdo != NULL) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   311
          if (mdo->would_profile()) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   312
            int mdo_i = mdo->invocation_count_delta();
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   313
            int mdo_b = mdo->backedge_count_delta();
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   314
            if ((this->*p)(mdo_i, mdo_b, cur_level)) {
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   315
              next_level = CompLevel_full_optimization;
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   316
            }
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   317
          } else {
8322
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   318
            next_level = CompLevel_full_optimization;
8f11ba61239f 7017434: Tiered needs to support reprofiling
iveresov
parents: 7397
diff changeset
   319
          }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   320
        }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   321
      }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   322
      break;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   323
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   324
  }
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10014
diff changeset
   325
  return MIN2(next_level, (CompLevel)TieredStopAtLevel);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   326
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   327
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   328
// Determine if a method should be compiled with a normal entry point at a different level.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   329
CompLevel SimpleThresholdPolicy::call_event(methodOop method,  CompLevel cur_level) {
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   330
  CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   331
                             common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   332
  CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   333
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   334
  // If OSR method level is greater than the regular method level, the levels should be
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   335
  // equalized by raising the regular method level in order to avoid OSRs during each
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   336
  // invocation of the method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   337
  if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   338
    methodDataOop mdo = method->method_data();
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   339
    guarantee(mdo != NULL, "MDO should not be NULL");
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   340
    if (mdo->invocation_count() >= 1) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   341
      next_level = CompLevel_full_optimization;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   342
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   343
  } else {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   344
    next_level = MAX2(osr_level, next_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   345
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   346
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   347
  return next_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   348
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   349
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   350
// Determine if we should do an OSR compilation of a given method.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   351
CompLevel SimpleThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) {
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   352
  CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   353
  if (cur_level == CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   354
    // If there is a live OSR method that means that we deopted to the interpreter
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   355
    // for the transition.
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   356
    CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   357
    if (osr_level > CompLevel_none) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   358
      return osr_level;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   359
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   360
  }
10013
714ad59b56cb 7058689: Tiered: Reprofiling doesn't happen in presence of level 4 OSR methods
iveresov
parents: 9625
diff changeset
   361
  return next_level;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   362
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   363
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   364
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   365
// Handle the invocation event.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   366
void SimpleThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh,
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   367
                                              CompLevel level, nmethod* nm, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   368
  if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   369
    CompLevel next_level = call_event(mh(), level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   370
    if (next_level != level) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   371
      compile(mh, InvocationEntryBci, next_level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   372
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   373
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   374
}
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   375
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   376
// Handle the back branch event. Notice that we can compile the method
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   377
// with a regular entry from here.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   378
void SimpleThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh,
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   379
                                                     int bci, CompLevel level, nmethod* nm, JavaThread* thread) {
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   380
  // If the method is already compiling, quickly bail out.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   381
  if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   382
    // Use loop event as an opportinity to also check there's been
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   383
    // enough calls.
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   384
    CompLevel cur_level = comp_level(mh());
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   385
    CompLevel next_level = call_event(mh(), cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   386
    CompLevel next_osr_level = loop_event(mh(), level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   387
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   388
    next_level = MAX2(next_level,
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   389
                      next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   390
    bool is_compiling = false;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   391
    if (next_level != cur_level) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   392
      compile(mh, InvocationEntryBci, next_level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   393
      is_compiling = true;
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   394
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   395
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   396
    // Do the OSR version
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   397
    if (!is_compiling && next_osr_level != level) {
11572
84afef481892 7131259: compile_method and CompilationPolicy::event shouldn't be declared TRAPS
iveresov
parents: 11192
diff changeset
   398
      compile(mh, bci, next_osr_level, thread);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   399
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   400
  }
970dc585ab63 6953144: Tiered compilation
iveresov
parents:
diff changeset
   401
}