Fri, 20 Sep 2013 10:53:28 +0200
8024974: Incorrect use of GC_locker::is_active()
Summary: SymbolTable and StringTable can make calls to GC_locker::is_active() outside a safepoint. This isn't safe because the GC_locker active state (lock count) is only updated at a safepoint and only remains valid as long as _needs_gc is true. However, outside a safepoint_needs_gc can change to false at any time, which makes it impossible to do a correct call to is_active() in that context. In this case these calls can just be removed since the input argument to basic_add() should never be on the heap and so there's no need to check the GC_locker state. This change also adjusts the assert() in is_active() to makes sure all calls to this function are always done under a safepoint.
Reviewed-by: brutisso, dcubed
Contributed-by: per.liden@oracle.com
jmasa@4196 | 1 | /* |
jmasa@4196 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
jmasa@4196 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jmasa@4196 | 4 | * |
jmasa@4196 | 5 | * This code is free software; you can redistribute it and/or modify it |
jmasa@4196 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jmasa@4196 | 7 | * published by the Free Software Foundation. |
jmasa@4196 | 8 | * |
jmasa@4196 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jmasa@4196 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jmasa@4196 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jmasa@4196 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jmasa@4196 | 13 | * accompanied this code). |
jmasa@4196 | 14 | * |
jmasa@4196 | 15 | * You should have received a copy of the GNU General Public License version |
jmasa@4196 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jmasa@4196 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jmasa@4196 | 18 | * |
jmasa@4196 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jmasa@4196 | 20 | * or visit www.oracle.com if you need additional information or have any |
jmasa@4196 | 21 | * questions. |
jmasa@4196 | 22 | * |
jmasa@4196 | 23 | */ |
jmasa@4196 | 24 | #ifndef SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 25 | #define SHARE_VM_MEMORY_METACHUNK_HPP |
jmasa@4196 | 26 | |
jmasa@4196 | 27 | // Metachunk - Quantum of allocation from a Virtualspace |
jmasa@4196 | 28 | // Metachunks are reused (when freed are put on a global freelist) and |
jmasa@4196 | 29 | // have no permanent association to a SpaceManager. |
jmasa@4196 | 30 | |
jmasa@4196 | 31 | // +--------------+ <- end |
jmasa@4196 | 32 | // | | --+ ---+ |
jmasa@4196 | 33 | // | | | free | |
jmasa@4196 | 34 | // | | | | |
jmasa@4196 | 35 | // | | | | capacity |
jmasa@4196 | 36 | // | | | | |
jmasa@4196 | 37 | // | | <- top --+ | |
jmasa@4196 | 38 | // | | ---+ | |
jmasa@4196 | 39 | // | | | used | |
jmasa@4196 | 40 | // | | | | |
jmasa@4196 | 41 | // | | | | |
jmasa@4196 | 42 | // +--------------+ <- bottom ---+ ---+ |
jmasa@4196 | 43 | |
jmasa@5007 | 44 | class VirtualSpaceNode; |
jmasa@5007 | 45 | |
jmasa@4196 | 46 | class Metachunk VALUE_OBJ_CLASS_SPEC { |
jmasa@4196 | 47 | // link to support lists of chunks |
jmasa@4196 | 48 | Metachunk* _next; |
jmasa@4196 | 49 | Metachunk* _prev; |
jmasa@5007 | 50 | VirtualSpaceNode* _container; |
jmasa@4196 | 51 | |
jmasa@4196 | 52 | MetaWord* _bottom; |
jmasa@4196 | 53 | MetaWord* _end; |
jmasa@4196 | 54 | MetaWord* _top; |
jmasa@4196 | 55 | size_t _word_size; |
jmasa@4196 | 56 | // Used in a guarantee() so included in the Product builds |
jmasa@4196 | 57 | // even through it is only for debugging. |
jmasa@4196 | 58 | bool _is_free; |
jmasa@4196 | 59 | |
jmasa@4196 | 60 | // Metachunks are allocated out of a MetadataVirtualSpace and |
jmasa@4196 | 61 | // and use some of its space to describe itself (plus alignment |
jmasa@4196 | 62 | // considerations). Metadata is allocated in the rest of the chunk. |
jmasa@4196 | 63 | // This size is the overhead of maintaining the Metachunk within |
jmasa@4196 | 64 | // the space. |
jmasa@4196 | 65 | static size_t _overhead; |
jmasa@4196 | 66 | |
jmasa@4196 | 67 | public: |
jmasa@5007 | 68 | Metachunk(size_t word_size , VirtualSpaceNode* container); |
jmasa@4196 | 69 | |
jmasa@4196 | 70 | // Used to add a Metachunk to a list of Metachunks |
jmasa@4196 | 71 | void set_next(Metachunk* v) { _next = v; assert(v != this, "Boom");} |
jmasa@4196 | 72 | void set_prev(Metachunk* v) { _prev = v; assert(v != this, "Boom");} |
jmasa@5007 | 73 | void set_container(VirtualSpaceNode* v) { _container = v; } |
jmasa@4196 | 74 | |
jmasa@4196 | 75 | MetaWord* allocate(size_t word_size); |
jmasa@4196 | 76 | |
jmasa@4196 | 77 | // Accessors |
jmasa@4196 | 78 | Metachunk* next() const { return _next; } |
jmasa@4196 | 79 | Metachunk* prev() const { return _prev; } |
jmasa@5007 | 80 | VirtualSpaceNode* container() const { return _container; } |
jmasa@4196 | 81 | MetaWord* bottom() const { return _bottom; } |
jmasa@4196 | 82 | MetaWord* end() const { return _end; } |
jmasa@4196 | 83 | MetaWord* top() const { return _top; } |
jmasa@4196 | 84 | size_t word_size() const { return _word_size; } |
jmasa@4196 | 85 | size_t size() const volatile { return _word_size; } |
jmasa@4196 | 86 | void set_size(size_t v) { _word_size = v; } |
jmasa@4196 | 87 | bool is_free() { return _is_free; } |
jmasa@4196 | 88 | void set_is_free(bool v) { _is_free = v; } |
jmasa@4196 | 89 | static size_t overhead() { return _overhead; } |
jmasa@4196 | 90 | void clear_next() { set_next(NULL); } |
jmasa@4196 | 91 | void link_prev(Metachunk* ptr) { set_prev(ptr); } |
jmasa@4196 | 92 | uintptr_t* end() { return ((uintptr_t*) this) + size(); } |
jmasa@4196 | 93 | bool cantCoalesce() const { return false; } |
jmasa@4196 | 94 | void link_next(Metachunk* ptr) { set_next(ptr); } |
jmasa@4196 | 95 | void link_after(Metachunk* ptr){ |
jmasa@4196 | 96 | link_next(ptr); |
jmasa@4196 | 97 | if (ptr != NULL) ptr->link_prev(this); |
jmasa@4196 | 98 | } |
jmasa@4196 | 99 | |
jmasa@4196 | 100 | // Reset top to bottom so chunk can be reused. |
jmasa@4382 | 101 | void reset_empty() { _top = (_bottom + _overhead); _next = NULL; _prev = NULL; } |
jmasa@4196 | 102 | bool is_empty() { return _top == (_bottom + _overhead); } |
jmasa@4196 | 103 | |
jmasa@4196 | 104 | // used (has been allocated) |
jmasa@4196 | 105 | // free (available for future allocations) |
jmasa@4196 | 106 | // capacity (total size of chunk) |
jmasa@4382 | 107 | size_t used_word_size() const; |
jmasa@4382 | 108 | size_t free_word_size() const; |
jmasa@4382 | 109 | size_t capacity_word_size()const; |
jmasa@4196 | 110 | |
jmasa@4196 | 111 | // Debug support |
jmasa@4196 | 112 | #ifdef ASSERT |
jmasa@4196 | 113 | void* prev_addr() const { return (void*)&_prev; } |
jmasa@4196 | 114 | void* next_addr() const { return (void*)&_next; } |
jmasa@4196 | 115 | void* size_addr() const { return (void*)&_word_size; } |
jmasa@4196 | 116 | #endif |
jmasa@4196 | 117 | bool verify_chunk_in_free_list(Metachunk* tc) const { return true; } |
jmasa@4196 | 118 | bool verify_par_locked() { return true; } |
jmasa@4196 | 119 | |
jmasa@4196 | 120 | void assert_is_mangled() const {/* Don't check "\*/} |
jmasa@4196 | 121 | |
coleenp@4304 | 122 | NOT_PRODUCT(void mangle();) |
jmasa@4196 | 123 | |
jmasa@4196 | 124 | void print_on(outputStream* st) const; |
jmasa@4196 | 125 | void verify(); |
jmasa@4196 | 126 | }; |
jmasa@4196 | 127 | #endif // SHARE_VM_MEMORY_METACHUNK_HPP |