src/share/vm/interpreter/oopMapCache.hpp

Thu, 30 Oct 2008 15:48:59 -0400

author
kamg
date
Thu, 30 Oct 2008 15:48:59 -0400
changeset 848
c7ec737733a6
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

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

mercurial