Sun, 11 Oct 2009 16:19:25 -0700
6888953: some calls to function-like macros are missing semicolons
Reviewed-by: pbk, kvn
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2006 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 | // InvocationCounters are used to trigger actions when a limit (threshold) is reached. |
duke@435 | 26 | // For different states, different limits and actions can be defined in the initialization |
duke@435 | 27 | // routine of InvocationCounters. |
duke@435 | 28 | // |
duke@435 | 29 | // Implementation notes: For space reasons, state & counter are both encoded in one word, |
duke@435 | 30 | // The state is encoded using some of the least significant bits, the counter is using the |
duke@435 | 31 | // more significant bits. The counter is incremented before a method is activated and an |
duke@435 | 32 | // action is triggered when when count() > limit(). |
duke@435 | 33 | |
duke@435 | 34 | class InvocationCounter VALUE_OBJ_CLASS_SPEC { |
duke@435 | 35 | friend class VMStructs; |
duke@435 | 36 | private: // bit no: |31 3| 2 | 1 0 | |
duke@435 | 37 | unsigned int _counter; // format: [count|carry|state] |
duke@435 | 38 | |
duke@435 | 39 | enum PrivateConstants { |
duke@435 | 40 | number_of_state_bits = 2, |
duke@435 | 41 | number_of_carry_bits = 1, |
duke@435 | 42 | number_of_noncount_bits = number_of_state_bits + number_of_carry_bits, |
duke@435 | 43 | number_of_count_bits = BitsPerInt - number_of_noncount_bits, |
duke@435 | 44 | state_limit = nth_bit(number_of_state_bits), |
duke@435 | 45 | count_grain = nth_bit(number_of_state_bits + number_of_carry_bits), |
duke@435 | 46 | count_limit = nth_bit(number_of_count_bits - 1), |
duke@435 | 47 | carry_mask = right_n_bits(number_of_carry_bits) << number_of_state_bits, |
duke@435 | 48 | state_mask = right_n_bits(number_of_state_bits), |
duke@435 | 49 | status_mask = right_n_bits(number_of_state_bits + number_of_carry_bits), |
duke@435 | 50 | count_mask = ((int)(-1) ^ status_mask) |
duke@435 | 51 | }; |
duke@435 | 52 | |
duke@435 | 53 | public: |
duke@435 | 54 | static int InterpreterInvocationLimit; // CompileThreshold scaled for interpreter use |
duke@435 | 55 | static int Tier1InvocationLimit; // CompileThreshold scaled for tier1 use |
duke@435 | 56 | static int Tier1BackEdgeLimit; // BackEdgeThreshold scaled for tier1 use |
duke@435 | 57 | |
duke@435 | 58 | static int InterpreterBackwardBranchLimit; // A separate threshold for on stack replacement |
duke@435 | 59 | |
duke@435 | 60 | static int InterpreterProfileLimit; // Profiling threshold scaled for interpreter use |
duke@435 | 61 | |
duke@435 | 62 | typedef address (*Action)(methodHandle method, TRAPS); |
duke@435 | 63 | |
duke@435 | 64 | enum PublicConstants { |
duke@435 | 65 | count_increment = count_grain, // use this value to increment the 32bit _counter word |
duke@435 | 66 | count_mask_value = count_mask // use this value to mask the backedge counter |
duke@435 | 67 | }; |
duke@435 | 68 | |
duke@435 | 69 | enum State { |
duke@435 | 70 | wait_for_nothing, // do nothing when count() > limit() |
duke@435 | 71 | wait_for_compile, // introduce nmethod when count() > limit() |
duke@435 | 72 | number_of_states // must be <= state_limit |
duke@435 | 73 | }; |
duke@435 | 74 | |
duke@435 | 75 | // Manipulation |
duke@435 | 76 | void reset(); // sets state to wait state |
duke@435 | 77 | void init(); // sets state into original state |
duke@435 | 78 | void set_state(State state); // sets state and initializes counter correspondingly |
duke@435 | 79 | inline void set(State state, int count); // sets state and counter |
duke@435 | 80 | inline void decay(); // decay counter (divide by two) |
duke@435 | 81 | void set_carry(); // set the sticky carry bit |
duke@435 | 82 | |
duke@435 | 83 | // Accessors |
duke@435 | 84 | State state() const { return (State)(_counter & state_mask); } |
duke@435 | 85 | bool carry() const { return (_counter & carry_mask) != 0; } |
duke@435 | 86 | int limit() const { return CompileThreshold; } |
duke@435 | 87 | Action action() const { return _action[state()]; } |
duke@435 | 88 | int count() const { return _counter >> number_of_noncount_bits; } |
duke@435 | 89 | |
duke@435 | 90 | int get_InvocationLimit() const { return InterpreterInvocationLimit >> number_of_noncount_bits; } |
duke@435 | 91 | int get_BackwardBranchLimit() const { return InterpreterBackwardBranchLimit >> number_of_noncount_bits; } |
duke@435 | 92 | int get_ProfileLimit() const { return InterpreterProfileLimit >> number_of_noncount_bits; } |
duke@435 | 93 | |
duke@435 | 94 | // Test counter using scaled limits like the asm interpreter would do rather than doing |
duke@435 | 95 | // the shifts to normalize the counter. |
duke@435 | 96 | |
duke@435 | 97 | bool reached_InvocationLimit() const { return _counter >= (unsigned int) InterpreterInvocationLimit; } |
duke@435 | 98 | bool reached_BackwardBranchLimit() const { return _counter >= (unsigned int) InterpreterBackwardBranchLimit; } |
duke@435 | 99 | |
duke@435 | 100 | // Do this just like asm interpreter does for max speed |
duke@435 | 101 | bool reached_ProfileLimit(InvocationCounter *back_edge_count) const { |
duke@435 | 102 | return (_counter && count_mask) + back_edge_count->_counter >= (unsigned int) InterpreterProfileLimit; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | void increment() { _counter += count_increment; } |
duke@435 | 106 | |
duke@435 | 107 | |
duke@435 | 108 | // Printing |
duke@435 | 109 | void print(); |
duke@435 | 110 | void print_short(); |
duke@435 | 111 | |
duke@435 | 112 | // Miscellaneous |
duke@435 | 113 | static ByteSize counter_offset() { return byte_offset_of(InvocationCounter, _counter); } |
duke@435 | 114 | static void reinitialize(bool delay_overflow); |
duke@435 | 115 | |
duke@435 | 116 | private: |
duke@435 | 117 | static int _init [number_of_states]; // the counter limits |
duke@435 | 118 | static Action _action[number_of_states]; // the actions |
duke@435 | 119 | |
duke@435 | 120 | static void def(State state, int init, Action action); |
duke@435 | 121 | static const char* state_as_string(State state); |
duke@435 | 122 | static const char* state_as_short_string(State state); |
duke@435 | 123 | }; |
duke@435 | 124 | |
duke@435 | 125 | inline void InvocationCounter::set(State state, int count) { |
duke@435 | 126 | assert(0 <= state && state < number_of_states, "illegal state"); |
duke@435 | 127 | int carry = (_counter & carry_mask); // the carry bit is sticky |
duke@435 | 128 | _counter = (count << number_of_noncount_bits) | carry | state; |
duke@435 | 129 | } |
duke@435 | 130 | |
duke@435 | 131 | inline void InvocationCounter::decay() { |
duke@435 | 132 | int c = count(); |
duke@435 | 133 | int new_count = c >> 1; |
duke@435 | 134 | // prevent from going to zero, to distinguish from never-executed methods |
duke@435 | 135 | if (c > 0 && new_count == 0) new_count = 1; |
duke@435 | 136 | set(state(), new_count); |
duke@435 | 137 | } |