Tue, 19 Aug 2014 02:05:49 -0700
8044406: JVM crash with JDK8 (build 1.8.0-b132) with G1 GC
Summary: Fill the last card that has been allocated into with a dummy object
Reviewed-by: tschatzl, mgerdin
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2014, 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_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/allocation.hpp" |
aoqi@0 | 29 | #include "memory/freeList.hpp" |
aoqi@0 | 30 | #include "runtime/globals.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | class CodeBlobClosure; |
aoqi@0 | 33 | |
aoqi@0 | 34 | class G1CodeRootChunk : public CHeapObj<mtGC> { |
aoqi@0 | 35 | private: |
aoqi@0 | 36 | static const int NUM_ENTRIES = 32; |
aoqi@0 | 37 | public: |
aoqi@0 | 38 | G1CodeRootChunk* _next; |
aoqi@0 | 39 | G1CodeRootChunk* _prev; |
aoqi@0 | 40 | |
aoqi@0 | 41 | nmethod** _top; |
aoqi@0 | 42 | |
aoqi@0 | 43 | nmethod* _data[NUM_ENTRIES]; |
aoqi@0 | 44 | |
aoqi@0 | 45 | nmethod** bottom() const { |
aoqi@0 | 46 | return (nmethod**) &(_data[0]); |
aoqi@0 | 47 | } |
aoqi@0 | 48 | |
aoqi@0 | 49 | nmethod** end() const { |
aoqi@0 | 50 | return (nmethod**) &(_data[NUM_ENTRIES]); |
aoqi@0 | 51 | } |
aoqi@0 | 52 | |
aoqi@0 | 53 | public: |
aoqi@0 | 54 | G1CodeRootChunk(); |
aoqi@0 | 55 | ~G1CodeRootChunk() {} |
aoqi@0 | 56 | |
aoqi@0 | 57 | static size_t word_size() { return (size_t)(align_size_up_(sizeof(G1CodeRootChunk), HeapWordSize) / HeapWordSize); } |
aoqi@0 | 58 | |
aoqi@0 | 59 | // FreeList "interface" methods |
aoqi@0 | 60 | |
aoqi@0 | 61 | G1CodeRootChunk* next() const { return _next; } |
aoqi@0 | 62 | G1CodeRootChunk* prev() const { return _prev; } |
aoqi@0 | 63 | void set_next(G1CodeRootChunk* v) { _next = v; assert(v != this, "Boom");} |
aoqi@0 | 64 | void set_prev(G1CodeRootChunk* v) { _prev = v; assert(v != this, "Boom");} |
aoqi@0 | 65 | void clear_next() { set_next(NULL); } |
aoqi@0 | 66 | void clear_prev() { set_prev(NULL); } |
aoqi@0 | 67 | |
aoqi@0 | 68 | size_t size() const { return word_size(); } |
aoqi@0 | 69 | |
aoqi@0 | 70 | void link_next(G1CodeRootChunk* ptr) { set_next(ptr); } |
aoqi@0 | 71 | void link_prev(G1CodeRootChunk* ptr) { set_prev(ptr); } |
aoqi@0 | 72 | void link_after(G1CodeRootChunk* ptr) { |
aoqi@0 | 73 | link_next(ptr); |
aoqi@0 | 74 | if (ptr != NULL) ptr->link_prev((G1CodeRootChunk*)this); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | bool is_free() { return true; } |
aoqi@0 | 78 | |
aoqi@0 | 79 | // New G1CodeRootChunk routines |
aoqi@0 | 80 | |
aoqi@0 | 81 | void reset(); |
aoqi@0 | 82 | |
aoqi@0 | 83 | bool is_empty() const { |
aoqi@0 | 84 | return _top == bottom(); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | bool is_full() const { |
aoqi@0 | 88 | return _top == (nmethod**)end(); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | bool contains(nmethod* method) { |
aoqi@0 | 92 | nmethod** cur = bottom(); |
aoqi@0 | 93 | while (cur != _top) { |
aoqi@0 | 94 | if (*cur == method) return true; |
aoqi@0 | 95 | cur++; |
aoqi@0 | 96 | } |
aoqi@0 | 97 | return false; |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | bool add(nmethod* method) { |
aoqi@0 | 101 | if (is_full()) return false; |
aoqi@0 | 102 | *_top = method; |
aoqi@0 | 103 | _top++; |
aoqi@0 | 104 | return true; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | bool remove(nmethod* method) { |
aoqi@0 | 108 | nmethod** cur = bottom(); |
aoqi@0 | 109 | while (cur != _top) { |
aoqi@0 | 110 | if (*cur == method) { |
aoqi@0 | 111 | memmove(cur, cur + 1, (_top - (cur + 1)) * sizeof(nmethod**)); |
aoqi@0 | 112 | _top--; |
aoqi@0 | 113 | return true; |
aoqi@0 | 114 | } |
aoqi@0 | 115 | cur++; |
aoqi@0 | 116 | } |
aoqi@0 | 117 | return false; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | void nmethods_do(CodeBlobClosure* blk); |
aoqi@0 | 121 | |
aoqi@0 | 122 | nmethod* pop() { |
aoqi@0 | 123 | if (is_empty()) { |
aoqi@0 | 124 | return NULL; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | _top--; |
aoqi@0 | 127 | return *_top; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | }; |
aoqi@0 | 130 | |
aoqi@0 | 131 | // Implements storage for a set of code roots. |
aoqi@0 | 132 | // All methods that modify the set are not thread-safe except if otherwise noted. |
aoqi@0 | 133 | class G1CodeRootSet VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 134 | private: |
aoqi@0 | 135 | // Global free chunk list management |
aoqi@0 | 136 | static FreeList<G1CodeRootChunk> _free_list; |
aoqi@0 | 137 | // Total number of chunks handed out |
aoqi@0 | 138 | static size_t _num_chunks_handed_out; |
aoqi@0 | 139 | |
aoqi@0 | 140 | static G1CodeRootChunk* new_chunk(); |
aoqi@0 | 141 | static void free_chunk(G1CodeRootChunk* chunk); |
aoqi@0 | 142 | // Free all elements of the given list. |
aoqi@0 | 143 | static void free_all_chunks(FreeList<G1CodeRootChunk>* list); |
aoqi@0 | 144 | |
aoqi@0 | 145 | // Return the chunk that contains the given nmethod, NULL otherwise. |
aoqi@0 | 146 | // Scans the list of chunks backwards, as this method is used to add new |
aoqi@0 | 147 | // entries, which are typically added in bulk for a single nmethod. |
aoqi@0 | 148 | G1CodeRootChunk* find(nmethod* method); |
aoqi@0 | 149 | void free(G1CodeRootChunk* chunk); |
aoqi@0 | 150 | |
aoqi@0 | 151 | size_t _length; |
aoqi@0 | 152 | FreeList<G1CodeRootChunk> _list; |
aoqi@0 | 153 | |
aoqi@0 | 154 | public: |
aoqi@0 | 155 | G1CodeRootSet(); |
aoqi@0 | 156 | ~G1CodeRootSet(); |
aoqi@0 | 157 | |
aoqi@0 | 158 | static void initialize(); |
aoqi@0 | 159 | static void purge_chunks(size_t keep_ratio); |
aoqi@0 | 160 | |
aoqi@0 | 161 | static size_t static_mem_size(); |
aoqi@0 | 162 | static size_t fl_mem_size(); |
aoqi@0 | 163 | |
aoqi@0 | 164 | // Search for the code blob from the recently allocated ones to find duplicates more quickly, as this |
aoqi@0 | 165 | // method is likely to be repeatedly called with the same nmethod. |
aoqi@0 | 166 | void add(nmethod* method); |
aoqi@0 | 167 | |
aoqi@0 | 168 | void remove(nmethod* method); |
aoqi@0 | 169 | nmethod* pop(); |
aoqi@0 | 170 | |
aoqi@0 | 171 | bool contains(nmethod* method); |
aoqi@0 | 172 | |
aoqi@0 | 173 | void clear(); |
aoqi@0 | 174 | |
aoqi@0 | 175 | void nmethods_do(CodeBlobClosure* blk) const; |
aoqi@0 | 176 | |
aoqi@0 | 177 | bool is_empty() { return length() == 0; } |
aoqi@0 | 178 | |
aoqi@0 | 179 | // Length in elements |
aoqi@0 | 180 | size_t length() const { return _length; } |
aoqi@0 | 181 | |
aoqi@0 | 182 | // Memory size in bytes taken by this set. |
aoqi@0 | 183 | size_t mem_size(); |
aoqi@0 | 184 | |
aoqi@0 | 185 | static void test() PRODUCT_RETURN; |
aoqi@0 | 186 | }; |
aoqi@0 | 187 | |
aoqi@0 | 188 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CODECACHEREMSET_HPP |