8290464: Optimize ResourceArea zapping on ResourceMark release

Reviewed-by: stuefe, zgu, coleenp
This commit is contained in:
Aleksey Shipilev
2022-07-22 11:12:49 +00:00
parent e9f97b2e8c
commit 7841e5cc38

View File

@@ -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
@@ -117,16 +117,34 @@ public:
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");
}
}
};