src/share/vm/interpreter/oopMapCache.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial