1
1
/*
2
- * Copyright (c) 2014, 2025 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2014, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
26
26
#define SHARE_MEMORY_GUARDEDMEMORY_HPP
27
27
28
28
#include " memory/allocation.hpp"
29
- #include " runtime/safefetch.hpp"
30
29
#include " utilities/globalDefinitions.hpp"
31
30
32
31
/* *
44
43
* |base_addr | 0xABABABABABABABAB | Head guard |
45
44
* |+16 | <size_t:user_size> | User data size |
46
45
* |+sizeof(uintptr_t) | <tag> | Tag word |
47
- * |+sizeof(uintptr_t) | <tag2> | Tag word |
48
46
* |+sizeof(void*) | 0xF1 <user_data> ( | User data |
49
47
* |+user_size | 0xABABABABABABABAB | Tail guard |
50
48
* -------------------------------------------------------------
51
49
*
52
50
* Where:
53
51
* - guard padding uses "badResourceValue" (0xAB)
54
- * - tag word and tag2 word are general purpose
52
+ * - tag word is general purpose
55
53
* - user data
56
54
* -- initially padded with "uninitBlockPad" (0xF1),
57
55
* -- to "freeBlockPad" (0xBA), when freed
@@ -116,11 +114,7 @@ class GuardedMemory : StackObj { // Wrapper on stack
116
114
u_char* c = (u_char*) _guard;
117
115
u_char* end = c + GUARD_SIZE;
118
116
while (c < end) {
119
- // We may not be able to dereference directly so use
120
- // SafeFetch. It doesn't matter if the value read happens
121
- // to be 0xFF as that is not what we expect anyway.
122
- u_char val = (u_char) SafeFetch32 ((int *)c, 0xFF );
123
- if (val != badResourceValue) {
117
+ if (*c != badResourceValue) {
124
118
return false ;
125
119
}
126
120
c++;
@@ -143,18 +137,13 @@ class GuardedMemory : StackObj { // Wrapper on stack
143
137
size_t _user_size;
144
138
};
145
139
void * _tag;
146
- void * _tag2;
147
140
public:
148
141
void set_user_size (const size_t usz) { _user_size = usz; }
149
142
size_t get_user_size () const { return _user_size; }
150
143
151
144
void set_tag (const void * tag) { _tag = (void *) tag; }
152
145
void * get_tag () const { return _tag; }
153
146
154
- void set_tag2 (const void * tag2) { _tag2 = (void *) tag2; }
155
- void * get_tag2 () const { return _tag2; }
156
-
157
-
158
147
}; // GuardedMemory::GuardHeader
159
148
160
149
// Guarded Memory...
@@ -173,11 +162,9 @@ class GuardedMemory : StackObj { // Wrapper on stack
173
162
* @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes.
174
163
* @param user_size the size of the user data to be wrapped.
175
164
* @param tag optional general purpose tag.
176
- * @param tag2 optional second general purpose tag.
177
165
*/
178
- GuardedMemory (void * base_ptr, const size_t user_size,
179
- const void * tag = nullptr , const void * tag2 = nullptr ) {
180
- wrap_with_guards (base_ptr, user_size, tag, tag2);
166
+ GuardedMemory (void * base_ptr, const size_t user_size, const void * tag = nullptr ) {
167
+ wrap_with_guards (base_ptr, user_size, tag);
181
168
}
182
169
183
170
/* *
@@ -202,19 +189,16 @@ class GuardedMemory : StackObj { // Wrapper on stack
202
189
* @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes.
203
190
* @param user_size the size of the user data to be wrapped.
204
191
* @param tag optional general purpose tag.
205
- * @param tag2 optional second general purpose tag.
206
192
*
207
193
* @return user data pointer (inner pointer to supplied "base_ptr").
208
194
*/
209
- void * wrap_with_guards (void * base_ptr, size_t user_size,
210
- const void * tag = nullptr , const void * tag2 = nullptr ) {
195
+ void * wrap_with_guards (void * base_ptr, size_t user_size, const void * tag = nullptr ) {
211
196
assert (base_ptr != nullptr , " Attempt to wrap null with memory guard" );
212
197
_base_addr = (u_char*)base_ptr;
213
198
get_head_guard ()->build ();
214
199
get_head_guard ()->set_user_size (user_size);
215
200
get_tail_guard ()->build ();
216
201
set_tag (tag);
217
- set_tag2 (tag2);
218
202
set_user_bytes (uninitBlockPad);
219
203
assert (verify_guards (), " Expected valid memory guards" );
220
204
return get_user_ptr ();
@@ -246,20 +230,6 @@ class GuardedMemory : StackObj { // Wrapper on stack
246
230
*/
247
231
void * get_tag () const { return get_head_guard ()->get_tag (); }
248
232
249
- /* *
250
- * Set the second general purpose tag.
251
- *
252
- * @param tag general purpose tag.
253
- */
254
- void set_tag2 (const void * tag) { get_head_guard ()->set_tag2 (tag); }
255
-
256
- /* *
257
- * Return the second general purpose tag.
258
- *
259
- * @return the second general purpose tag, defaults to null.
260
- */
261
- void * get_tag2 () const { return get_head_guard ()->get_tag2 (); }
262
-
263
233
/* *
264
234
* Return the size of the user data.
265
235
*
@@ -332,12 +302,10 @@ class GuardedMemory : StackObj { // Wrapper on stack
332
302
* @param ptr the memory to be copied
333
303
* @param len the length of the copy
334
304
* @param tag optional general purpose tag (see GuardedMemory::get_tag())
335
- * @param tag2 optional general purpose tag (see GuardedMemory::get_tag2())
336
305
*
337
306
* @return guarded wrapped memory pointer to the user area, or null if OOM.
338
307
*/
339
- static void * wrap_copy (const void * p, const size_t len,
340
- const void * tag = nullptr , const void * tag2 = nullptr );
308
+ static void * wrap_copy (const void * p, const size_t len, const void * tag = nullptr );
341
309
342
310
/* *
343
311
* Free wrapped copy.
0 commit comments