Wed, 13 Mar 2013 09:44:45 +0100
8009761: Deoptimization on sparc doesn't set Llast_SP correctly in the interpreter frames it creates
Summary: deoptimization doesn't set up callee frames so that they restore caller frames correctly.
Reviewed-by: kvn
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |
stefank@2314 | 26 | #define SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "oops/generateOopMap.hpp" |
stefank@2325 | 29 | #include "runtime/mutex.hpp" |
stefank@2314 | 30 | |
duke@435 | 31 | // A Cache for storing (method, bci) -> oopMap. |
duke@435 | 32 | // The memory management system uses the cache when locating object |
duke@435 | 33 | // references in an interpreted frame. |
duke@435 | 34 | // |
coleenp@4037 | 35 | // OopMapCache's are allocated lazily per InstanceKlass. |
duke@435 | 36 | |
duke@435 | 37 | // The oopMap (InterpreterOopMap) is stored as a bit mask. If the |
duke@435 | 38 | // bit_mask can fit into two words it is stored in |
duke@435 | 39 | // the _bit_mask array, otherwise it is allocated on the heap. |
duke@435 | 40 | // For OopMapCacheEntry the bit_mask is allocated in the C heap |
duke@435 | 41 | // because these entries persist between garbage collections. |
duke@435 | 42 | // For InterpreterOopMap the bit_mask is allocated in |
duke@435 | 43 | // a resource area for better performance. InterpreterOopMap |
duke@435 | 44 | // should only be created and deleted during same garbage collection. |
duke@435 | 45 | // |
duke@435 | 46 | // If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used |
duke@435 | 47 | // per entry instead of one. In all cases, |
duke@435 | 48 | // the first bit is set to indicate oops as opposed to other |
duke@435 | 49 | // values. If the second bit is available, |
duke@435 | 50 | // it is set for dead values. We get the following encoding: |
duke@435 | 51 | // |
duke@435 | 52 | // 00 live value |
duke@435 | 53 | // 01 live oop |
duke@435 | 54 | // 10 dead value |
duke@435 | 55 | // 11 <unused> (we cannot distinguish between dead oops or values with the current oop map generator) |
duke@435 | 56 | |
duke@435 | 57 | |
duke@435 | 58 | class OffsetClosure { |
duke@435 | 59 | public: |
duke@435 | 60 | virtual void offset_do(int offset) = 0; |
duke@435 | 61 | }; |
duke@435 | 62 | |
duke@435 | 63 | |
duke@435 | 64 | class InterpreterOopMap: ResourceObj { |
duke@435 | 65 | friend class OopMapCache; |
duke@435 | 66 | |
duke@435 | 67 | public: |
duke@435 | 68 | enum { |
duke@435 | 69 | N = 2, // the number of words reserved |
duke@435 | 70 | // for inlined mask storage |
duke@435 | 71 | small_mask_limit = N * BitsPerWord, // the maximum number of bits |
duke@435 | 72 | // available for small masks, |
duke@435 | 73 | // small_mask_limit can be set to 0 |
duke@435 | 74 | // for testing bit_mask allocation |
duke@435 | 75 | |
duke@435 | 76 | #ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 77 | bits_per_entry = 2, |
duke@435 | 78 | dead_bit_number = 1, |
duke@435 | 79 | #else |
duke@435 | 80 | bits_per_entry = 1, |
duke@435 | 81 | #endif |
duke@435 | 82 | oop_bit_number = 0 |
duke@435 | 83 | }; |
duke@435 | 84 | |
duke@435 | 85 | private: |
coleenp@4037 | 86 | Method* _method; // the method for which the mask is valid |
duke@435 | 87 | unsigned short _bci; // the bci for which the mask is valid |
duke@435 | 88 | int _mask_size; // the mask size in bits |
duke@435 | 89 | int _expression_stack_size; // the size of the expression stack in slots |
duke@435 | 90 | |
duke@435 | 91 | protected: |
duke@435 | 92 | intptr_t _bit_mask[N]; // the bit mask if |
duke@435 | 93 | // mask_size <= small_mask_limit, |
duke@435 | 94 | // ptr to bit mask otherwise |
duke@435 | 95 | // "protected" so that sub classes can |
duke@435 | 96 | // access it without using trickery in |
duke@435 | 97 | // methd bit_mask(). |
duke@435 | 98 | #ifdef ASSERT |
duke@435 | 99 | bool _resource_allocate_bit_mask; |
duke@435 | 100 | #endif |
duke@435 | 101 | |
duke@435 | 102 | // access methods |
coleenp@4037 | 103 | Method* method() const { return _method; } |
coleenp@4037 | 104 | void set_method(Method* v) { _method = v; } |
duke@435 | 105 | int bci() const { return _bci; } |
duke@435 | 106 | void set_bci(int v) { _bci = v; } |
duke@435 | 107 | int mask_size() const { return _mask_size; } |
duke@435 | 108 | void set_mask_size(int v) { _mask_size = v; } |
duke@435 | 109 | int number_of_entries() const { return mask_size() / bits_per_entry; } |
duke@435 | 110 | // Test bit mask size and return either the in-line bit mask or allocated |
duke@435 | 111 | // bit mask. |
duke@435 | 112 | uintptr_t* bit_mask() { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); } |
duke@435 | 113 | |
duke@435 | 114 | // return the word size of_bit_mask. mask_size() <= 4 * MAX_USHORT |
duke@435 | 115 | size_t mask_word_size() { |
duke@435 | 116 | return (mask_size() + BitsPerWord - 1) / BitsPerWord; |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | uintptr_t entry_at(int offset) { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); } |
duke@435 | 120 | |
duke@435 | 121 | void set_expression_stack_size(int sz) { _expression_stack_size = sz; } |
duke@435 | 122 | |
duke@435 | 123 | #ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 124 | bool is_dead(int offset) { return (entry_at(offset) & (1 << dead_bit_number)) != 0; } |
duke@435 | 125 | #endif |
duke@435 | 126 | |
duke@435 | 127 | // Lookup |
duke@435 | 128 | bool match(methodHandle method, int bci) { return _method == method() && _bci == bci; } |
duke@435 | 129 | bool is_empty(); |
duke@435 | 130 | |
duke@435 | 131 | // Initialization |
duke@435 | 132 | void initialize(); |
duke@435 | 133 | |
duke@435 | 134 | public: |
duke@435 | 135 | InterpreterOopMap(); |
duke@435 | 136 | ~InterpreterOopMap(); |
duke@435 | 137 | |
duke@435 | 138 | // Copy the OopMapCacheEntry in parameter "from" into this |
duke@435 | 139 | // InterpreterOopMap. If the _bit_mask[0] in "from" points to |
duke@435 | 140 | // allocated space (i.e., the bit mask was to large to hold |
duke@435 | 141 | // in-line), allocate the space from a Resource area. |
duke@435 | 142 | void resource_copy(OopMapCacheEntry* from); |
duke@435 | 143 | |
duke@435 | 144 | void iterate_oop(OffsetClosure* oop_closure); |
duke@435 | 145 | void print(); |
duke@435 | 146 | |
duke@435 | 147 | bool is_oop (int offset) { return (entry_at(offset) & (1 << oop_bit_number )) != 0; } |
duke@435 | 148 | |
duke@435 | 149 | int expression_stack_size() { return _expression_stack_size; } |
duke@435 | 150 | |
duke@435 | 151 | #ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 152 | void iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure); |
duke@435 | 153 | #endif |
duke@435 | 154 | }; |
duke@435 | 155 | |
zgu@3900 | 156 | class OopMapCache : public CHeapObj<mtClass> { |
duke@435 | 157 | private: |
duke@435 | 158 | enum { _size = 32, // Use fixed size for now |
duke@435 | 159 | _probe_depth = 3 // probe depth in case of collisions |
duke@435 | 160 | }; |
duke@435 | 161 | |
duke@435 | 162 | OopMapCacheEntry* _array; |
duke@435 | 163 | |
duke@435 | 164 | unsigned int hash_value_for(methodHandle method, int bci); |
duke@435 | 165 | OopMapCacheEntry* entry_at(int i) const; |
duke@435 | 166 | |
duke@435 | 167 | Mutex _mut; |
duke@435 | 168 | |
duke@435 | 169 | void flush(); |
duke@435 | 170 | |
duke@435 | 171 | public: |
duke@435 | 172 | OopMapCache(); |
duke@435 | 173 | ~OopMapCache(); // free up memory |
duke@435 | 174 | |
duke@435 | 175 | // flush cache entry is occupied by an obsolete method |
duke@435 | 176 | void flush_obsolete_entries(); |
duke@435 | 177 | |
duke@435 | 178 | // Returns the oopMap for (method, bci) in parameter "entry". |
duke@435 | 179 | // Returns false if an oop map was not found. |
duke@435 | 180 | void lookup(methodHandle method, int bci, InterpreterOopMap* entry); |
duke@435 | 181 | |
duke@435 | 182 | // Compute an oop map without updating the cache or grabbing any locks (for debugging) |
duke@435 | 183 | static void compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry); |
duke@435 | 184 | |
duke@435 | 185 | // Returns total no. of bytes allocated as part of OopMapCache's |
duke@435 | 186 | static long memory_usage() PRODUCT_RETURN0; |
duke@435 | 187 | }; |
stefank@2314 | 188 | |
stefank@2314 | 189 | #endif // SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP |