Mon, 25 Jun 2012 21:33:35 -0400
7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
Summary: Cannot delete _buckets and HashtableEntries in shared space (CDS)
Reviewed-by: acorn, kvn, dlong, dcubed, kamg
duke@435 | 1 | /* |
jrose@1934 | 2 | * Copyright (c) 1998, 2010, 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_CODE_OOPRECORDER_HPP |
stefank@2314 | 26 | #define SHARE_VM_CODE_OOPRECORDER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "runtime/handles.hpp" |
stefank@2314 | 29 | #include "utilities/growableArray.hpp" |
stefank@2314 | 30 | |
duke@435 | 31 | // Recording and retrieval of oop relocations in compiled code. |
duke@435 | 32 | |
duke@435 | 33 | class CodeBlob; |
duke@435 | 34 | |
duke@435 | 35 | class OopRecorder : public ResourceObj { |
duke@435 | 36 | public: |
duke@435 | 37 | // A two-way mapping from positive indexes to oop handles. |
duke@435 | 38 | // The zero index is reserved for a constant (sharable) null. |
duke@435 | 39 | // Indexes may not be negative. |
duke@435 | 40 | |
duke@435 | 41 | // Use the given arena to manage storage, if not NULL. |
duke@435 | 42 | // By default, uses the current ResourceArea. |
duke@435 | 43 | OopRecorder(Arena* arena = NULL); |
duke@435 | 44 | |
duke@435 | 45 | // Generate a new index on which CodeBlob::oop_addr_at will work. |
duke@435 | 46 | // allocate_index and find_index never return the same index, |
duke@435 | 47 | // and allocate_index never returns the same index twice. |
duke@435 | 48 | // In fact, two successive calls to allocate_index return successive ints. |
duke@435 | 49 | int allocate_index(jobject h) { |
duke@435 | 50 | return add_handle(h, false); |
duke@435 | 51 | } |
duke@435 | 52 | |
duke@435 | 53 | // For a given jobject, this will return the same index repeatedly. |
duke@435 | 54 | // The index can later be given to oop_at to retrieve the oop. |
duke@435 | 55 | // However, the oop must not be changed via CodeBlob::oop_addr_at. |
duke@435 | 56 | int find_index(jobject h) { |
duke@435 | 57 | int index = maybe_find_index(h); |
duke@435 | 58 | if (index < 0) { // previously unallocated |
duke@435 | 59 | index = add_handle(h, true); |
duke@435 | 60 | } |
duke@435 | 61 | return index; |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | // variant of find_index which does not allocate if not found (yields -1) |
duke@435 | 65 | int maybe_find_index(jobject h); |
duke@435 | 66 | |
duke@435 | 67 | // returns the size of the generated oop table, for sizing the CodeBlob. |
duke@435 | 68 | // must be called after all oops are allocated! |
duke@435 | 69 | int oop_size(); |
duke@435 | 70 | |
duke@435 | 71 | // Retrieve the oop handle at a given index. |
duke@435 | 72 | jobject handle_at(int index); |
duke@435 | 73 | |
duke@435 | 74 | int element_count() { |
duke@435 | 75 | // there is always a NULL virtually present as first object |
duke@435 | 76 | return _handles->length() + first_index; |
duke@435 | 77 | } |
duke@435 | 78 | |
twisti@1918 | 79 | // copy the generated oop table to nmethod |
twisti@1918 | 80 | void copy_to(nmethod* nm); // => nm->copy_oops(_handles) |
duke@435 | 81 | |
duke@435 | 82 | bool is_unused() { return _handles == NULL && !_complete; } |
duke@435 | 83 | #ifdef ASSERT |
duke@435 | 84 | bool is_complete() { return _complete; } |
duke@435 | 85 | #endif |
duke@435 | 86 | |
duke@435 | 87 | private: |
duke@435 | 88 | // leaky hash table of handle => index, to help detect duplicate insertion |
duke@435 | 89 | class IndexCache: public ResourceObj { |
duke@435 | 90 | // This class is only used by the OopRecorder class. |
duke@435 | 91 | friend class OopRecorder; |
duke@435 | 92 | enum { |
duke@435 | 93 | _log_cache_size = 9, |
duke@435 | 94 | _cache_size = (1<<_log_cache_size), |
duke@435 | 95 | // Index entries are ints. The LSBit is a collision indicator. |
duke@435 | 96 | _collision_bit_shift = 0, |
duke@435 | 97 | _collision_bit = 1, |
duke@435 | 98 | _index_shift = _collision_bit_shift+1 |
duke@435 | 99 | }; |
duke@435 | 100 | int _cache[_cache_size]; |
duke@435 | 101 | static juint cache_index(jobject handle) { |
duke@435 | 102 | juint ci = (int) (intptr_t) handle; |
duke@435 | 103 | ci ^= ci >> (BitsPerByte*2); |
duke@435 | 104 | ci += ci >> (BitsPerByte*1); |
duke@435 | 105 | return ci & (_cache_size-1); |
duke@435 | 106 | } |
duke@435 | 107 | int* cache_location(jobject handle) { |
duke@435 | 108 | return &_cache[ cache_index(handle) ]; |
duke@435 | 109 | } |
duke@435 | 110 | static bool cache_location_collision(int* cloc) { |
duke@435 | 111 | return ((*cloc) & _collision_bit) != 0; |
duke@435 | 112 | } |
duke@435 | 113 | static int cache_location_index(int* cloc) { |
duke@435 | 114 | return (*cloc) >> _index_shift; |
duke@435 | 115 | } |
duke@435 | 116 | static void set_cache_location_index(int* cloc, int index) { |
duke@435 | 117 | int cval0 = (*cloc); |
duke@435 | 118 | int cval1 = (index << _index_shift); |
duke@435 | 119 | if (cval0 != 0 && cval1 != cval0) cval1 += _collision_bit; |
duke@435 | 120 | (*cloc) = cval1; |
duke@435 | 121 | } |
duke@435 | 122 | IndexCache(); |
duke@435 | 123 | }; |
duke@435 | 124 | |
duke@435 | 125 | // Helper function; returns false for NULL or Universe::non_oop_word(). |
duke@435 | 126 | inline bool is_real_jobject(jobject h); |
duke@435 | 127 | |
duke@435 | 128 | void maybe_initialize(); |
duke@435 | 129 | int add_handle(jobject h, bool make_findable); |
duke@435 | 130 | |
duke@435 | 131 | enum { null_index = 0, first_index = 1, index_cache_threshold = 20 }; |
duke@435 | 132 | |
duke@435 | 133 | GrowableArray<jobject>* _handles; // ordered list (first is always NULL) |
duke@435 | 134 | GrowableArray<int>* _no_finds; // all unfindable indexes; usually empty |
duke@435 | 135 | IndexCache* _indexes; // map: jobject -> its probable index |
duke@435 | 136 | Arena* _arena; |
duke@435 | 137 | bool _complete; |
duke@435 | 138 | |
duke@435 | 139 | #ifdef ASSERT |
duke@435 | 140 | static int _find_index_calls, _hit_indexes, _missed_indexes; |
duke@435 | 141 | #endif |
duke@435 | 142 | }; |
stefank@2314 | 143 | |
stefank@2314 | 144 | #endif // SHARE_VM_CODE_OOPRECORDER_HPP |