8268265: MutableSpaceUsedHelper::take_sample() hits assert(left >= right) failed: avoid overflow
Reviewed-by: tschatzl, iwalulya
This commit is contained in:
parent
b66001a594
commit
c98d50848b
src/hotspot/share/gc
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,6 +26,10 @@
|
||||
#include "gc/parallel/spaceCounters.hpp"
|
||||
#include "memory/allocation.inline.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
|
||||
SpaceCounters::SpaceCounters(const char* name, int ordinal, size_t max_size,
|
||||
@ -68,3 +72,24 @@ SpaceCounters::SpaceCounters(const char* name, int ordinal, size_t max_size,
|
||||
SpaceCounters::~SpaceCounters() {
|
||||
FREE_C_HEAP_ARRAY(char, _name_space);
|
||||
}
|
||||
|
||||
static volatile size_t last_used_in_bytes = 0;
|
||||
|
||||
void SpaceCounters::update_used() {
|
||||
size_t new_used = _object_space->used_in_bytes();
|
||||
Atomic::store(&last_used_in_bytes, new_used);
|
||||
_used->set_value(new_used);
|
||||
}
|
||||
|
||||
jlong MutableSpaceUsedHelper::take_sample() {
|
||||
// Sampling may occur during GC, possibly while GC is updating the space.
|
||||
// The space can be in an inconsistent state during such an update. We
|
||||
// don't want to block sampling for the duration of a GC. Instead, skip
|
||||
// sampling in that case, using the last recorded value.
|
||||
assert(!Heap_lock->owned_by_self(), "precondition");
|
||||
if (Heap_lock->try_lock()) {
|
||||
Atomic::store(&last_used_in_bytes, _m->used_in_bytes());
|
||||
Heap_lock->unlock();
|
||||
}
|
||||
return Atomic::load(&last_used_in_bytes);
|
||||
}
|
||||
|
@ -58,9 +58,7 @@ class SpaceCounters: public CHeapObj<mtGC> {
|
||||
_capacity->set_value(_object_space->capacity_in_bytes());
|
||||
}
|
||||
|
||||
inline void update_used() {
|
||||
_used->set_value(_object_space->used_in_bytes());
|
||||
}
|
||||
void update_used();
|
||||
|
||||
inline void update_all() {
|
||||
update_used();
|
||||
@ -77,9 +75,7 @@ class MutableSpaceUsedHelper: public PerfLongSampleHelper {
|
||||
public:
|
||||
MutableSpaceUsedHelper(MutableSpace* m) : _m(m) { }
|
||||
|
||||
inline jlong take_sample() {
|
||||
return _m->used_in_bytes();
|
||||
}
|
||||
jlong take_sample() override;
|
||||
};
|
||||
|
||||
#endif // SHARE_GC_PARALLEL_SPACECOUNTERS_HPP
|
||||
|
@ -72,8 +72,12 @@ void CSpaceCounters::update_capacity() {
|
||||
_capacity->set_value(_space->capacity());
|
||||
}
|
||||
|
||||
static volatile size_t last_used_in_bytes = 0;
|
||||
|
||||
void CSpaceCounters::update_used() {
|
||||
_used->set_value(_space->used());
|
||||
size_t new_used = _space->used();
|
||||
Atomic::store(&last_used_in_bytes, new_used);
|
||||
_used->set_value(new_used);
|
||||
}
|
||||
|
||||
void CSpaceCounters::update_all() {
|
||||
@ -82,5 +86,14 @@ void CSpaceCounters::update_all() {
|
||||
}
|
||||
|
||||
jlong ContiguousSpaceUsedHelper::take_sample(){
|
||||
return _space->used();
|
||||
// Sampling may occur during GC, possibly while GC is updating the space.
|
||||
// The space can be in an inconsistent state during such an update. We
|
||||
// don't want to block sampling for the duration of a GC. Instead, skip
|
||||
// sampling in that case, using the last recorded value.
|
||||
assert(!Heap_lock->owned_by_self(), "precondition");
|
||||
if (Heap_lock->try_lock()) {
|
||||
Atomic::store(&last_used_in_bytes, _space->used());
|
||||
Heap_lock->unlock();
|
||||
}
|
||||
return Atomic::load(&last_used_in_bytes);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -54,9 +54,9 @@ class CSpaceCounters: public CHeapObj<mtGC> {
|
||||
|
||||
~CSpaceCounters();
|
||||
|
||||
virtual void update_capacity();
|
||||
virtual void update_used();
|
||||
virtual void update_all();
|
||||
void update_capacity();
|
||||
void update_used();
|
||||
void update_all();
|
||||
|
||||
const char* name_space() const { return _name_space; }
|
||||
};
|
||||
@ -68,7 +68,7 @@ class ContiguousSpaceUsedHelper : public PerfLongSampleHelper {
|
||||
public:
|
||||
ContiguousSpaceUsedHelper(ContiguousSpace* space) : _space(space) { }
|
||||
|
||||
jlong take_sample();
|
||||
jlong take_sample() override;
|
||||
};
|
||||
|
||||
#endif // SHARE_GC_SERIAL_CSPACECOUNTERS_HPP
|
||||
|
Loading…
x
Reference in New Issue
Block a user