src/share/vm/interpreter/oopMapCache.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9448
73d689add964
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
kevinw@9351 2 * Copyright (c) 1997, 2018, 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 {
sspitsyn@7668 69 N = 4, // 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 bits_per_entry = 2,
aoqi@0 77 dead_bit_number = 1,
aoqi@0 78 oop_bit_number = 0
aoqi@0 79 };
aoqi@0 80
aoqi@0 81 private:
aoqi@0 82 Method* _method; // the method for which the mask is valid
aoqi@0 83 unsigned short _bci; // the bci for which the mask is valid
aoqi@0 84 int _mask_size; // the mask size in bits
aoqi@0 85 int _expression_stack_size; // the size of the expression stack in slots
aoqi@0 86
aoqi@0 87 protected:
aoqi@0 88 intptr_t _bit_mask[N]; // the bit mask if
aoqi@0 89 // mask_size <= small_mask_limit,
aoqi@0 90 // ptr to bit mask otherwise
aoqi@0 91 // "protected" so that sub classes can
aoqi@0 92 // access it without using trickery in
aoqi@0 93 // methd bit_mask().
aoqi@0 94 #ifdef ASSERT
aoqi@0 95 bool _resource_allocate_bit_mask;
aoqi@0 96 #endif
aoqi@0 97
aoqi@0 98 // access methods
aoqi@0 99 Method* method() const { return _method; }
mgronlun@7215 100 void set_method(Method* v) { _method = v; }
aoqi@0 101 int bci() const { return _bci; }
aoqi@0 102 void set_bci(int v) { _bci = v; }
aoqi@0 103 int mask_size() const { return _mask_size; }
aoqi@0 104 void set_mask_size(int v) { _mask_size = v; }
aoqi@0 105 // Test bit mask size and return either the in-line bit mask or allocated
aoqi@0 106 // bit mask.
mgronlun@7215 107 uintptr_t* bit_mask() const { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); }
aoqi@0 108
aoqi@0 109 // return the word size of_bit_mask. mask_size() <= 4 * MAX_USHORT
mgronlun@7215 110 size_t mask_word_size() const {
aoqi@0 111 return (mask_size() + BitsPerWord - 1) / BitsPerWord;
aoqi@0 112 }
aoqi@0 113
mgronlun@7215 114 uintptr_t entry_at(int offset) const { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); }
aoqi@0 115
mgronlun@7215 116 void set_expression_stack_size(int sz) { _expression_stack_size = sz; }
aoqi@0 117
aoqi@0 118 // Lookup
mgronlun@7215 119 bool match(methodHandle method, int bci) const { return _method == method() && _bci == bci; }
mgronlun@7215 120 bool is_empty() const;
aoqi@0 121
aoqi@0 122 // Initialization
aoqi@0 123 void initialize();
aoqi@0 124
aoqi@0 125 public:
aoqi@0 126 InterpreterOopMap();
aoqi@0 127 ~InterpreterOopMap();
aoqi@0 128
aoqi@0 129 // Copy the OopMapCacheEntry in parameter "from" into this
aoqi@0 130 // InterpreterOopMap. If the _bit_mask[0] in "from" points to
aoqi@0 131 // allocated space (i.e., the bit mask was to large to hold
aoqi@0 132 // in-line), allocate the space from a Resource area.
aoqi@0 133 void resource_copy(OopMapCacheEntry* from);
aoqi@0 134
mgronlun@7215 135 void iterate_oop(OffsetClosure* oop_closure) const;
mgronlun@7215 136 void print() const;
aoqi@0 137
mgronlun@7215 138 int number_of_entries() const { return mask_size() / bits_per_entry; }
sspitsyn@7668 139 bool is_dead(int offset) const { return (entry_at(offset) & (1 << dead_bit_number)) != 0; }
mgronlun@7215 140 bool is_oop (int offset) const { return (entry_at(offset) & (1 << oop_bit_number )) != 0; }
aoqi@0 141
mgronlun@7215 142 int expression_stack_size() const { return _expression_stack_size; }
aoqi@0 143
aoqi@0 144 #ifdef ENABLE_ZAP_DEAD_LOCALS
aoqi@0 145 void iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure);
aoqi@0 146 #endif
aoqi@0 147 };
aoqi@0 148
aoqi@0 149 class OopMapCache : public CHeapObj<mtClass> {
aoqi@0 150 private:
aoqi@0 151 enum { _size = 32, // Use fixed size for now
aoqi@0 152 _probe_depth = 3 // probe depth in case of collisions
aoqi@0 153 };
aoqi@0 154
aoqi@0 155 OopMapCacheEntry* _array;
aoqi@0 156
mgronlun@7215 157 unsigned int hash_value_for(methodHandle method, int bci) const;
aoqi@0 158 OopMapCacheEntry* entry_at(int i) const;
aoqi@0 159
mgronlun@7215 160 mutable Mutex _mut;
aoqi@0 161
aoqi@0 162 void flush();
aoqi@0 163
aoqi@0 164 public:
aoqi@0 165 OopMapCache();
aoqi@0 166 ~OopMapCache(); // free up memory
aoqi@0 167
aoqi@0 168 // flush cache entry is occupied by an obsolete method
aoqi@0 169 void flush_obsolete_entries();
aoqi@0 170
aoqi@0 171 // Returns the oopMap for (method, bci) in parameter "entry".
aoqi@0 172 // Returns false if an oop map was not found.
mgronlun@7215 173 void lookup(methodHandle method, int bci, InterpreterOopMap* entry) const;
aoqi@0 174
aoqi@0 175 // Compute an oop map without updating the cache or grabbing any locks (for debugging)
aoqi@0 176 static void compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry);
aoqi@0 177
aoqi@0 178 // Returns total no. of bytes allocated as part of OopMapCache's
kevinw@9351 179 static size_t memory_usage() PRODUCT_RETURN0;
aoqi@0 180 };
aoqi@0 181
aoqi@0 182 #endif // SHARE_VM_INTERPRETER_OOPMAPCACHE_HPP

mercurial