Thu, 30 Oct 2008 15:48:59 -0400
6756528: Bytecodes::special_length_at reads past end of code buffer
Summary: Add end-of-buffer indicator for paths used by the verifier
Reviewed-by: acorn, coleenp
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_invocationCounter.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Implementation of InvocationCounter |
duke@435 | 30 | |
duke@435 | 31 | void InvocationCounter::init() { |
duke@435 | 32 | _counter = 0; // reset all the bits, including the sticky carry |
duke@435 | 33 | reset(); |
duke@435 | 34 | } |
duke@435 | 35 | |
duke@435 | 36 | void InvocationCounter::reset() { |
duke@435 | 37 | // Only reset the state and don't make the method look like it's never |
duke@435 | 38 | // been executed |
duke@435 | 39 | set_state(wait_for_compile); |
duke@435 | 40 | } |
duke@435 | 41 | |
duke@435 | 42 | void InvocationCounter::set_carry() { |
duke@435 | 43 | _counter |= carry_mask; |
duke@435 | 44 | |
duke@435 | 45 | // The carry bit now indicates that this counter had achieved a very |
duke@435 | 46 | // large value. Now reduce the value, so that the method can be |
duke@435 | 47 | // executed many more times before re-entering the VM. |
duke@435 | 48 | int old_count = count(); |
duke@435 | 49 | int new_count = MIN2(old_count, (int) (CompileThreshold / 2)); |
duke@435 | 50 | if (old_count != new_count) set(state(), new_count); |
duke@435 | 51 | } |
duke@435 | 52 | |
duke@435 | 53 | |
duke@435 | 54 | void InvocationCounter::set_state(State state) { |
duke@435 | 55 | assert(0 <= state && state < number_of_states, "illegal state"); |
duke@435 | 56 | int init = _init[state]; |
duke@435 | 57 | // prevent from going to zero, to distinguish from never-executed methods |
duke@435 | 58 | if (init == 0 && count() > 0) init = 1; |
duke@435 | 59 | int carry = (_counter & carry_mask); // the carry bit is sticky |
duke@435 | 60 | _counter = (init << number_of_noncount_bits) | carry | state; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | |
duke@435 | 64 | void InvocationCounter::print() { |
duke@435 | 65 | tty->print_cr("invocation count: up = %d, limit = %d, carry = %s, state = %s", |
duke@435 | 66 | count(), limit(), |
duke@435 | 67 | carry() ? "true" : "false", |
duke@435 | 68 | state_as_string(state())); |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | void InvocationCounter::print_short() { |
duke@435 | 72 | tty->print(" [%d%s;%s]", count(), carry()?"+carry":"", state_as_short_string(state())); |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | // Initialization |
duke@435 | 76 | |
duke@435 | 77 | int InvocationCounter::_init [InvocationCounter::number_of_states]; |
duke@435 | 78 | InvocationCounter::Action InvocationCounter::_action[InvocationCounter::number_of_states]; |
duke@435 | 79 | int InvocationCounter::InterpreterInvocationLimit; |
duke@435 | 80 | int InvocationCounter::InterpreterBackwardBranchLimit; |
duke@435 | 81 | int InvocationCounter::InterpreterProfileLimit; |
duke@435 | 82 | |
duke@435 | 83 | // Tier1 limits |
duke@435 | 84 | int InvocationCounter::Tier1InvocationLimit; |
duke@435 | 85 | int InvocationCounter::Tier1BackEdgeLimit; |
duke@435 | 86 | |
duke@435 | 87 | |
duke@435 | 88 | |
duke@435 | 89 | const char* InvocationCounter::state_as_string(State state) { |
duke@435 | 90 | switch (state) { |
duke@435 | 91 | case wait_for_nothing : return "wait_for_nothing"; |
duke@435 | 92 | case wait_for_compile : return "wait_for_compile"; |
duke@435 | 93 | } |
duke@435 | 94 | ShouldNotReachHere(); |
duke@435 | 95 | return NULL; |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | const char* InvocationCounter::state_as_short_string(State state) { |
duke@435 | 99 | switch (state) { |
duke@435 | 100 | case wait_for_nothing : return "not comp."; |
duke@435 | 101 | case wait_for_compile : return "compileable"; |
duke@435 | 102 | } |
duke@435 | 103 | ShouldNotReachHere(); |
duke@435 | 104 | return NULL; |
duke@435 | 105 | } |
duke@435 | 106 | |
duke@435 | 107 | |
duke@435 | 108 | static address do_nothing(methodHandle method, TRAPS) { |
duke@435 | 109 | // dummy action for inactive invocation counters |
duke@435 | 110 | method->invocation_counter()->set_carry(); |
duke@435 | 111 | method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
duke@435 | 112 | return NULL; |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | |
duke@435 | 116 | static address do_decay(methodHandle method, TRAPS) { |
duke@435 | 117 | // decay invocation counters so compilation gets delayed |
duke@435 | 118 | method->invocation_counter()->decay(); |
duke@435 | 119 | return NULL; |
duke@435 | 120 | } |
duke@435 | 121 | |
duke@435 | 122 | |
duke@435 | 123 | void InvocationCounter::def(State state, int init, Action action) { |
duke@435 | 124 | assert(0 <= state && state < number_of_states, "illegal state"); |
duke@435 | 125 | assert(0 <= init && init < count_limit, "initial value out of range"); |
duke@435 | 126 | _init [state] = init; |
duke@435 | 127 | _action[state] = action; |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | address dummy_invocation_counter_overflow(methodHandle m, TRAPS) { |
duke@435 | 131 | ShouldNotReachHere(); |
duke@435 | 132 | return NULL; |
duke@435 | 133 | } |
duke@435 | 134 | |
duke@435 | 135 | void InvocationCounter::reinitialize(bool delay_overflow) { |
duke@435 | 136 | // define states |
duke@435 | 137 | guarantee((int)number_of_states <= (int)state_limit, "adjust number_of_state_bits"); |
duke@435 | 138 | def(wait_for_nothing, 0, do_nothing); |
duke@435 | 139 | if (delay_overflow) { |
duke@435 | 140 | def(wait_for_compile, 0, do_decay); |
duke@435 | 141 | } else { |
duke@435 | 142 | def(wait_for_compile, 0, dummy_invocation_counter_overflow); |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | InterpreterInvocationLimit = CompileThreshold << number_of_noncount_bits; |
duke@435 | 146 | InterpreterProfileLimit = ((CompileThreshold * InterpreterProfilePercentage) / 100)<< number_of_noncount_bits; |
duke@435 | 147 | Tier1InvocationLimit = Tier2CompileThreshold << number_of_noncount_bits; |
duke@435 | 148 | Tier1BackEdgeLimit = Tier2BackEdgeThreshold << number_of_noncount_bits; |
duke@435 | 149 | |
duke@435 | 150 | // When methodData is collected, the backward branch limit is compared against a |
duke@435 | 151 | // methodData counter, rather than an InvocationCounter. In the former case, we |
duke@435 | 152 | // don't need the shift by number_of_noncount_bits, but we do need to adjust |
duke@435 | 153 | // the factor by which we scale the threshold. |
duke@435 | 154 | if (ProfileInterpreter) { |
duke@435 | 155 | InterpreterBackwardBranchLimit = (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; |
duke@435 | 156 | } else { |
duke@435 | 157 | InterpreterBackwardBranchLimit = ((CompileThreshold * OnStackReplacePercentage) / 100) << number_of_noncount_bits; |
duke@435 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | assert(0 <= InterpreterBackwardBranchLimit, |
duke@435 | 161 | "OSR threshold should be non-negative"); |
duke@435 | 162 | assert(0 <= InterpreterProfileLimit && |
duke@435 | 163 | InterpreterProfileLimit <= InterpreterInvocationLimit, |
duke@435 | 164 | "profile threshold should be less than the compilation threshold " |
duke@435 | 165 | "and non-negative"); |
duke@435 | 166 | } |
duke@435 | 167 | |
duke@435 | 168 | void invocationCounter_init() { |
duke@435 | 169 | InvocationCounter::reinitialize(DelayCompilationDuringStartup); |
duke@435 | 170 | } |