Skip to content

Commit

Permalink
ResourceMarkLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
reinrich committed Nov 12, 2024
1 parent 5b5f97a commit 08a10f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/memory/arena.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Chunk {

// Fast allocation of memory
class Arena : public CHeapObjBase {
friend class ResourceMarkLogger;
public:
enum class Tag: uint8_t {
#define ARENA_TAG_ENUM(name, str, desc) tag_##name,
Expand Down
14 changes: 14 additions & 0 deletions src/hotspot/share/memory/resourceArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "precompiled.hpp"
#include "logging/logStream.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.inline.hpp"
#include "nmt/memTracker.hpp"
Expand Down Expand Up @@ -57,6 +58,19 @@ void ResourceArea::verify_has_resource_mark() {
}
}
}
ResourceMarkLogger::~ResourceMarkLogger() {
LogTarget(Debug, newcode) _lt;
if (_lt.develop_is_enabled()) {
LogStream _ls(_lt);
ResourceArea::SavedState ss = _rm._impl._saved_state;
ResourceArea* ra = _rm._impl._area;
size_t free_on_entry_b = pointer_delta(ss._max, ss._hwm, 1);
size_t used_on_entry_b = ss._size_in_bytes - free_on_entry_b;
size_t free_now_b = pointer_delta(ra->_max, ra->_hwm, 1);
size_t alloc_b = (ra->size_in_bytes() - free_now_b - used_on_entry_b);
_ls.print_cr("%s: used_kb:" SIZE_FORMAT " alloc_kb:" SIZE_FORMAT" alloc_b:" SIZE_FORMAT, _id, used_on_entry_b/K, alloc_b/K, alloc_b);
}
}

#endif // ASSERT

Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/share/memory/resourceArea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ResourceArea: public Arena {
// rollback to that mark.
class SavedState {
friend class ResourceArea;
friend class ResourceMarkLogger;
Chunk* _chunk;
char* _hwm;
char* _max;
Expand Down Expand Up @@ -154,6 +155,7 @@ class ResourceArea: public Arena {

// Shared part of implementation for ResourceMark and DeoptResourceMark.
class ResourceMarkImpl {
friend class ResourceMarkLogger;
ResourceArea* _area; // Resource area to stack allocate
ResourceArea::SavedState _saved_state;

Expand Down Expand Up @@ -181,6 +183,7 @@ class ResourceMarkImpl {
};

class ResourceMark: public StackObj {
friend class ResourceMarkLogger;
const ResourceMarkImpl _impl;
#ifdef ASSERT
Thread* _thread;
Expand Down Expand Up @@ -217,6 +220,14 @@ class ResourceMark: public StackObj {
void reset_to_mark() { _impl.reset_to_mark(); }
};

class ResourceMarkLogger {
ResourceMark& _rm;
const char* _id;
public:
ResourceMarkLogger(ResourceMark& rm, const char* id) : _rm(rm), _id(id) {}
~ResourceMarkLogger();
};

//------------------------------DeoptResourceMark-----------------------------------
// A deopt resource mark releases all resources allocated after it was constructed
// when the destructor is called. Typically used as a local variable. It differs
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/opto/postaloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ bool PhaseChaitin::eliminate_copy_of_constant(Node* val, Node* n,
void PhaseChaitin::merge_multidefs() {
Compile::TracePhase tp("mergeMultidefs", &timers[_t_mergeMultidefs]);
ResourceMark rm;
ResourceMarkLogger(rm, "merge_multidefs");
// Keep track of the defs seen in registers and collect their uses in the block.
RegToDefUseMap reg2defuse(_max_reg, _max_reg, RegDefUse());
for (uint i = 0; i < _cfg.number_of_blocks(); i++) {
Expand Down

0 comments on commit 08a10f8

Please sign in to comment.