This commit is contained in:
Jesper Wilhelmsson 2017-10-22 00:10:29 +02:00
commit a9f136ec2e
3 changed files with 61 additions and 11 deletions

View File

@ -53,6 +53,7 @@ char* PerfMemory::_top = NULL;
size_t PerfMemory::_capacity = 0;
jint PerfMemory::_initialized = false;
PerfDataPrologue* PerfMemory::_prologue = NULL;
bool PerfMemory::_destroyed = false;
void perfMemory_init() {
@ -64,7 +65,7 @@ void perfMemory_init() {
void perfMemory_exit() {
if (!UsePerfData) return;
if (!PerfMemory::is_initialized()) return;
if (!PerfMemory::is_usable()) return;
// Only destroy PerfData objects if we're at a safepoint and the
// StatSampler is not active. Otherwise, we risk removing PerfData
@ -88,7 +89,7 @@ void perfMemory_exit() {
void PerfMemory::initialize() {
if (_prologue != NULL)
if (is_initialized())
// initialization already performed
return;
@ -160,7 +161,7 @@ void PerfMemory::initialize() {
void PerfMemory::destroy() {
if (_prologue == NULL) return;
if (!is_usable()) return;
if (_start != NULL && _prologue->overflow != 0) {
@ -196,11 +197,7 @@ void PerfMemory::destroy() {
delete_memory_region();
}
_start = NULL;
_end = NULL;
_top = NULL;
_prologue = NULL;
_capacity = 0;
_destroyed = true;
}
// allocate an aligned block of memory from the PerfData memory
@ -213,7 +210,7 @@ char* PerfMemory::alloc(size_t size) {
MutexLocker ml(PerfDataMemAlloc_lock);
assert(_prologue != NULL, "called before initialization");
assert(is_usable(), "called before init or after destroy");
// check that there is enough memory for this request
if ((_top + size) >= _end) {
@ -238,6 +235,8 @@ char* PerfMemory::alloc(size_t size) {
void PerfMemory::mark_updated() {
if (!UsePerfData) return;
assert(is_usable(), "called before init or after destroy");
_prologue->mod_time_stamp = os::elapsed_counter();
}
@ -268,3 +267,7 @@ char* PerfMemory::get_perfdata_file_path() {
return dest_file;
}
bool PerfMemory::is_initialized() {
return OrderAccess::load_acquire(&_initialized) != 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2017, 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
@ -113,6 +113,7 @@ static const size_t UINT_CHARS = 10;
*/
class PerfMemory : AllStatic {
friend class VMStructs;
friend class PerfMemoryTest;
private:
static char* _start;
static char* _end;
@ -120,6 +121,7 @@ class PerfMemory : AllStatic {
static size_t _capacity;
static PerfDataPrologue* _prologue;
static jint _initialized;
static bool _destroyed;
static void create_memory_region(size_t sizep);
static void delete_memory_region();
@ -135,7 +137,9 @@ class PerfMemory : AllStatic {
static char* end() { return _end; }
static size_t used() { return (size_t) (_top - _start); }
static size_t capacity() { return _capacity; }
static bool is_initialized() { return _initialized != 0; }
static bool is_initialized();
static bool is_destroyed() { return _destroyed; }
static bool is_usable() { return is_initialized() && !is_destroyed(); }
static bool contains(char* addr) {
return ((_start != NULL) && (addr >= _start) && (addr < _end));
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2017, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "precompiled.hpp"
#include "runtime/perfMemory.hpp"
#include "unittest.hpp"
class PerfMemoryTest : public ::testing::Test {
public:
static char* top() { return PerfMemory::_top; }
static PerfDataPrologue* prologue() { return PerfMemory::_prologue; }
};
TEST_VM_F(PerfMemoryTest, destroy) {
PerfMemory::destroy();
ASSERT_NE(PerfMemory::start(), (char*)NULL) << "PerfMemory::_start should not be NULL";
ASSERT_NE(PerfMemory::end(), (char*)NULL) << "PerfMemory::_end should not be NULL";
ASSERT_NE(PerfMemoryTest::top(), (char*)NULL) << "PerfMemory::_top should not be NULL";
ASSERT_NE(PerfMemoryTest::prologue(), (PerfDataPrologue*)NULL) << "PerfMemory::_prologue should not be NULL";
ASSERT_NE(PerfMemory::capacity(), (size_t)0) << "PerfMemory::_capacity should not be 0";
}