Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8251850: Refactor ResourceMark and DeoptResourceMark for better code …
…sharing

Move saved state to ResourceArea, merge most of marks into shared helper.

Reviewed-by: stuefe, iklam, tschatzl, xliu, vlivanov
  • Loading branch information
Kim Barrett committed Aug 26, 2020
1 parent 9f421d0 commit 19df711dc9054ae2497d89480f199e04a8cbbf91
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 186 deletions.
@@ -93,7 +93,6 @@ class Chunk: CHeapObj<mtChunk> {
// Fast allocation of memory
class Arena : public CHeapObj<mtNone> {
protected:
friend class ResourceMark;
friend class HandleMark;
friend class NoHandleMark;
friend class VMStructs;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -25,7 +25,7 @@
#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.inline.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/atomic.hpp"
#include "runtime/thread.inline.hpp"
#include "services/memTracker.hpp"

@@ -40,9 +40,25 @@ void ResourceArea::bias_to(MEMFLAGS new_flags) {
}
}

//------------------------------ResourceMark-----------------------------------
debug_only(int ResourceArea::_warned;) // to suppress multiple warnings
#ifdef ASSERT

void ResourceArea::verify_has_resource_mark() {
if (_nesting <= 0) {
// Only report the first occurrence of an allocating thread that
// is missing a ResourceMark, to avoid possible recursive errors
// in error handling.
static volatile bool reported = false;
if (!Atomic::load(&reported)) {
if (!Atomic::cmpxchg(&reported, false, true)) {
fatal("memory leak: allocating without ResourceMark");
}
}
}
}

#endif // ASSERT

//------------------------------ResourceMark-----------------------------------
// The following routines are declared in allocation.hpp and used everywhere:

// Allocation in thread-local resource area
@@ -60,30 +76,3 @@ extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_s
extern void resource_free_bytes( char *old, size_t size ) {
Thread::current()->resource_area()->Afree(old, size);
}

#ifdef ASSERT
ResourceMark::ResourceMark(Thread *thread) {
assert(thread == Thread::current(), "not the current thread");
initialize(thread);
}

DeoptResourceMark::DeoptResourceMark(Thread *thread) {
assert(thread == Thread::current(), "not the current thread");
initialize(thread);
}
#endif


//-------------------------------------------------------------------------------
// Non-product code
#ifndef PRODUCT

void ResourceMark::free_malloced_objects() {
Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm);
}

void DeoptResourceMark::free_malloced_objects() {
Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm);
}

#endif

0 comments on commit 19df711

Please sign in to comment.