Skip to content

Commit 295cf44

Browse files
committed
8290464: Optimize ResourceArea zapping on ResourceMark release
Backport-of: 7841e5cc387ba595f73f40b3a0d00d7e36df15ea
1 parent b8a0a22 commit 295cf44

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/hotspot/share/memory/resourceArea.hpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -117,16 +117,34 @@ class ResourceArea: public Arena {
117117
size_in_bytes(), state._size_in_bytes);
118118
set_size_in_bytes(state._size_in_bytes);
119119
state._chunk->next_chop();
120+
assert(_hwm != state._hwm, "Sanity check: HWM moves when we have later chunks");
120121
} else {
121122
assert(size_in_bytes() == state._size_in_bytes, "Sanity check");
122123
}
123-
_chunk = state._chunk; // Roll back to saved chunk.
124-
_hwm = state._hwm;
125-
_max = state._max;
126124

127-
// Clear out this chunk (to detect allocation bugs)
128-
if (ZapResourceArea) {
129-
memset(state._hwm, badResourceValue, state._max - state._hwm);
125+
if (_hwm != state._hwm) {
126+
// HWM moved: resource area was used. Roll back!
127+
128+
char* replaced_hwm = _hwm;
129+
130+
_chunk = state._chunk;
131+
_hwm = state._hwm;
132+
_max = state._max;
133+
134+
// Clear out this chunk (to detect allocation bugs).
135+
// If current chunk contains the replaced HWM, this means we are
136+
// doing the rollback within the same chunk, and we only need to
137+
// clear up to replaced HWM.
138+
if (ZapResourceArea) {
139+
char* limit = _chunk->contains(replaced_hwm) ? replaced_hwm : _max;
140+
assert(limit >= _hwm, "Sanity check: non-negative memset size");
141+
memset(_hwm, badResourceValue, limit - _hwm);
142+
}
143+
} else {
144+
// No allocations. Nothing to rollback. Check it.
145+
assert(_chunk == state._chunk, "Sanity check: idempotence");
146+
assert(_hwm == state._hwm, "Sanity check: idempotence");
147+
assert(_max == state._max, "Sanity check: idempotence");
130148
}
131149
}
132150
};

0 commit comments

Comments
 (0)