Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/hotspot/share/memory/resourceArea.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
Expand Down Expand Up @@ -117,16 +117,34 @@ class ResourceArea: public Arena {
size_in_bytes(), state._size_in_bytes);
set_size_in_bytes(state._size_in_bytes);
state._chunk->next_chop();
assert(_hwm != state._hwm, "Sanity check: HWM moves when we have later chunks");
} else {
assert(size_in_bytes() == state._size_in_bytes, "Sanity check");
}
_chunk = state._chunk; // Roll back to saved chunk.
_hwm = state._hwm;
_max = state._max;

// Clear out this chunk (to detect allocation bugs)
if (ZapResourceArea) {
memset(state._hwm, badResourceValue, state._max - state._hwm);
if (_hwm != state._hwm) {
// HWM moved: resource area was used. Roll back!

char* replaced_hwm = _hwm;

_chunk = state._chunk;
_hwm = state._hwm;
_max = state._max;

// Clear out this chunk (to detect allocation bugs).
// If current chunk contains the replaced HWM, this means we are
// doing the rollback within the same chunk, and we only need to
// clear up to replaced HWM.
if (ZapResourceArea) {
char* limit = _chunk->contains(replaced_hwm) ? replaced_hwm : _max;
assert(limit >= _hwm, "Sanity check: non-negative memset size");
memset(_hwm, badResourceValue, limit - _hwm);
}
} else {
// No allocations. Nothing to rollback. Check it.
assert(_chunk == state._chunk, "Sanity check: idempotence");
assert(_hwm == state._hwm, "Sanity check: idempotence");
assert(_max == state._max, "Sanity check: idempotence");
}
}
};
Expand Down