src/share/vm/memory/referencePolicy.cpp

Wed, 12 Oct 2011 10:25:51 -0700

author
johnc
date
Wed, 12 Oct 2011 10:25:51 -0700
changeset 3188
d1bdeef3e3e2
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

7098282: G1: assert(interval >= 0) failed: Sanity check, referencePolicy.cpp: 76
Summary: There is a race between one thread successfully forwarding and copying the klass mirror for the SoftReference class (including the static master clock) and another thread attempting to use the master clock while attempting to discover a soft reference object. Maintain a shadow copy of the soft reference master clock and use the shadow during reference discovery and reference processing.
Reviewed-by: tonyp, brutisso, ysr

duke@435 1 /*
johnc@3188 2 * Copyright (c) 2000, 2011, 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"
stefank@2314 26 #include "classfile/javaClasses.hpp"
stefank@2314 27 #include "memory/referencePolicy.hpp"
stefank@2314 28 #include "memory/universe.hpp"
stefank@2314 29 #include "runtime/arguments.hpp"
stefank@2314 30 #include "runtime/globals.hpp"
duke@435 31
duke@435 32 LRUCurrentHeapPolicy::LRUCurrentHeapPolicy() {
ysr@892 33 setup();
ysr@888 34 }
ysr@888 35
ysr@888 36 // Capture state (of-the-VM) information needed to evaluate the policy
ysr@892 37 void LRUCurrentHeapPolicy::setup() {
duke@435 38 _max_interval = (Universe::get_heap_free_at_last_gc() / M) * SoftRefLRUPolicyMSPerMB;
duke@435 39 assert(_max_interval >= 0,"Sanity check");
duke@435 40 }
duke@435 41
duke@435 42 // The oop passed in is the SoftReference object, and not
duke@435 43 // the object the SoftReference points to.
johnc@3188 44 bool LRUCurrentHeapPolicy::should_clear_reference(oop p,
johnc@3188 45 jlong timestamp_clock) {
johnc@3188 46 jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
duke@435 47 assert(interval >= 0, "Sanity check");
duke@435 48
duke@435 49 // The interval will be zero if the ref was accessed since the last scavenge/gc.
duke@435 50 if(interval <= _max_interval) {
duke@435 51 return false;
duke@435 52 }
duke@435 53
duke@435 54 return true;
duke@435 55 }
duke@435 56
duke@435 57 /////////////////////// MaxHeap //////////////////////
duke@435 58
duke@435 59 LRUMaxHeapPolicy::LRUMaxHeapPolicy() {
ysr@892 60 setup();
ysr@888 61 }
ysr@888 62
ysr@888 63 // Capture state (of-the-VM) information needed to evaluate the policy
ysr@892 64 void LRUMaxHeapPolicy::setup() {
duke@435 65 size_t max_heap = MaxHeapSize;
duke@435 66 max_heap -= Universe::get_heap_used_at_last_gc();
duke@435 67 max_heap /= M;
duke@435 68
duke@435 69 _max_interval = max_heap * SoftRefLRUPolicyMSPerMB;
duke@435 70 assert(_max_interval >= 0,"Sanity check");
duke@435 71 }
duke@435 72
duke@435 73 // The oop passed in is the SoftReference object, and not
duke@435 74 // the object the SoftReference points to.
johnc@3188 75 bool LRUMaxHeapPolicy::should_clear_reference(oop p,
johnc@3188 76 jlong timestamp_clock) {
johnc@3188 77 jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
duke@435 78 assert(interval >= 0, "Sanity check");
duke@435 79
duke@435 80 // The interval will be zero if the ref was accessed since the last scavenge/gc.
duke@435 81 if(interval <= _max_interval) {
duke@435 82 return false;
duke@435 83 }
duke@435 84
duke@435 85 return true;
duke@435 86 }

mercurial