src/share/vm/memory/memRegion.cpp

Fri, 20 Sep 2013 10:53:28 +0200

author
stefank
date
Fri, 20 Sep 2013 10:53:28 +0200
changeset 5769
2c022e432e10
parent 5614
9758d9f36299
child 6876
710a3c8b516e
child 7074
833b0f92429a
permissions
-rw-r--r--

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

duke@435 1 /*
coleenp@5614 2 * Copyright (c) 2000, 2013, 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 #include "precompiled.hpp"
minqi@5103 26 #include "memory/allocation.hpp"
minqi@5103 27 #include "memory/allocation.inline.hpp"
stefank@2314 28 #include "memory/memRegion.hpp"
stefank@2314 29 #include "runtime/globals.hpp"
stefank@2314 30
duke@435 31 // A very simple data structure representing a contigous word-aligned
duke@435 32 // region of address space.
duke@435 33
duke@435 34 MemRegion MemRegion::intersection(const MemRegion mr2) const {
duke@435 35 MemRegion res;
duke@435 36 HeapWord* res_start = MAX2(start(), mr2.start());
duke@435 37 HeapWord* res_end = MIN2(end(), mr2.end());
duke@435 38 if (res_start < res_end) {
duke@435 39 res.set_start(res_start);
duke@435 40 res.set_end(res_end);
duke@435 41 }
duke@435 42 return res;
duke@435 43 }
duke@435 44
duke@435 45 MemRegion MemRegion::_union(const MemRegion mr2) const {
duke@435 46 // If one region is empty, return the other
duke@435 47 if (is_empty()) return mr2;
duke@435 48 if (mr2.is_empty()) return MemRegion(start(), end());
duke@435 49
duke@435 50 // Otherwise, regions must overlap or be adjacent
duke@435 51 assert(((start() <= mr2.start()) && (end() >= mr2.start())) ||
duke@435 52 ((mr2.start() <= start()) && (mr2.end() >= start())),
duke@435 53 "non-adjacent or overlapping regions");
duke@435 54 MemRegion res;
duke@435 55 HeapWord* res_start = MIN2(start(), mr2.start());
duke@435 56 HeapWord* res_end = MAX2(end(), mr2.end());
duke@435 57 res.set_start(res_start);
duke@435 58 res.set_end(res_end);
duke@435 59 return res;
duke@435 60 }
duke@435 61
duke@435 62 MemRegion MemRegion::minus(const MemRegion mr2) const {
duke@435 63 // There seem to be 6 cases:
duke@435 64 // |this MemRegion|
duke@435 65 // |strictly below|
duke@435 66 // |overlap beginning|
duke@435 67 // |interior|
duke@435 68 // |overlap ending|
duke@435 69 // |strictly above|
duke@435 70 // |completely overlapping|
duke@435 71 // We can't deal with an interior case because it would
duke@435 72 // produce two disjoint regions as a result.
duke@435 73 // We aren't trying to be optimal in the number of tests below,
duke@435 74 // but the order is important to distinguish the strictly cases
duke@435 75 // from the overlapping cases.
duke@435 76 if (mr2.end() <= start()) {
duke@435 77 // strictly below
duke@435 78 return MemRegion(start(), end());
duke@435 79 }
duke@435 80 if (mr2.start() <= start() && mr2.end() <= end()) {
duke@435 81 // overlap beginning
duke@435 82 return MemRegion(mr2.end(), end());
duke@435 83 }
duke@435 84 if (mr2.start() >= end()) {
duke@435 85 // strictly above
duke@435 86 return MemRegion(start(), end());
duke@435 87 }
duke@435 88 if (mr2.start() >= start() && mr2.end() >= end()) {
duke@435 89 // overlap ending
duke@435 90 return MemRegion(start(), mr2.start());
duke@435 91 }
duke@435 92 if (mr2.start() <= start() && mr2.end() >= end()) {
duke@435 93 // completely overlapping
duke@435 94 return MemRegion();
duke@435 95 }
duke@435 96 if (mr2.start() > start() && mr2.end() < end()) {
duke@435 97 // interior
duke@435 98 guarantee(false, "MemRegion::minus, but interior");
duke@435 99 return MemRegion();
duke@435 100 }
duke@435 101 ShouldNotReachHere();
duke@435 102 return MemRegion();
duke@435 103 }
minqi@5103 104
coleenp@5614 105 void* MemRegion::operator new(size_t size) throw() {
minqi@5103 106 return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL);
minqi@5103 107 }
minqi@5103 108
coleenp@5614 109 void* MemRegion::operator new [](size_t size) throw() {
minqi@5103 110 return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL);
minqi@5103 111 }
minqi@5103 112 void MemRegion::operator delete(void* p) {
minqi@5103 113 FreeHeap(p, mtGC);
minqi@5103 114 }
minqi@5103 115
minqi@5103 116 void MemRegion::operator delete [](void* p) {
minqi@5103 117 FreeHeap(p, mtGC);
minqi@5103 118 }
minqi@5103 119

mercurial