Mercurial > hg > graal-compiler
annotate src/share/vm/memory/guardedMemory.hpp @ 20591:28051f14c328
8043158: Crash in CodeSweeperSweepNoFlushTest in CompileQueue::free_all()
Summary: Acquire lock before calling notify()
Reviewed-by: twisti, thartmann
author | anoll |
---|---|
date | Fri, 20 Jun 2014 09:25:13 +0200 |
parents | fa62fb12cdca |
children |
rev | line source |
---|---|
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
1 /* |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
4 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
8 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
13 * accompanied this code). |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
14 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
18 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
21 * questions. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
22 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
23 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
24 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
25 #ifndef SHARE_VM_MEMORY_GUARDED_MEMORY_HPP |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
26 #define SHARE_VM_MEMORY_GUARDED_MEMORY_HPP |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
27 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
28 #include "memory/allocation.hpp" |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
29 #include "utilities/globalDefinitions.hpp" |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
30 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
31 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
32 * Guarded memory for detecting buffer overrun. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
33 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
34 * Allows allocations to be wrapped with padded bytes of a known byte pattern, |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
35 * that is a "guard". Guard patterns may be verified to detect buffer overruns. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
36 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
37 * Primarily used by "debug malloc" and "checked JNI". |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
38 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
39 * Memory layout: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
40 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
41 * |Offset | Content | Description | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
42 * |------------------------------------------------------------ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
43 * |base_addr | 0xABABABABABABABAB | Head guard | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
44 * |+16 | <size_t:user_size> | User data size | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
45 * |+sizeof(uintptr_t) | <tag> | Tag word | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
46 * |+sizeof(void*) | 0xF1 <user_data> ( | User data | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
47 * |+user_size | 0xABABABABABABABAB | Tail guard | |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
48 * ------------------------------------------------------------- |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
49 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
50 * Where: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
51 * - guard padding uses "badResourceValue" (0xAB) |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
52 * - tag word is general purpose |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
53 * - user data |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
54 * -- initially padded with "uninitBlockPad" (0xF1), |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
55 * -- to "freeBlockPad" (0xBA), when freed |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
56 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
57 * Usage: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
58 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
59 * * Allocations: one may wrap allocations with guard memory: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
60 * <code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
61 * Thing* alloc_thing() { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
62 * void* mem = user_alloc_fn(GuardedMemory::get_total_size(sizeof(thing))); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
63 * GuardedMemory guarded(mem, sizeof(thing)); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
64 * return (Thing*) guarded.get_user_ptr(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
65 * } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
66 * </code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
67 * * Verify: memory guards are still in tact |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
68 * <code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
69 * bool verify_thing(Thing* thing) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
70 * GuardedMemory guarded((void*)thing); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
71 * return guarded.verify_guards(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
72 * } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
73 * </code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
74 * * Free: one may mark bytes as freed (further debugging support) |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
75 * <code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
76 * void free_thing(Thing* thing) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
77 * GuardedMemory guarded((void*)thing); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
78 * assert(guarded.verify_guards(), "Corrupt thing"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
79 * user_free_fn(guards.release_for_freeing(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
80 * } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
81 * </code> |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
82 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
83 class GuardedMemory : StackObj { // Wrapper on stack |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
84 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
85 // Private inner classes for memory layout... |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
86 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
87 protected: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
88 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
89 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
90 * Guard class for header and trailer known pattern to test for overwrites. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
91 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
92 class Guard { // Class for raw memory (no vtbl allowed) |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
93 friend class GuardedMemory; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
94 protected: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
95 enum { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
96 GUARD_SIZE = 16 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
97 }; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
98 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
99 u_char _guard[GUARD_SIZE]; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
100 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
101 public: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
102 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
103 void build() { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
104 u_char* c = _guard; // Possibly unaligned if tail guard |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
105 u_char* end = c + GUARD_SIZE; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
106 while (c < end) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
107 *c = badResourceValue; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
108 c++; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
109 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
110 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
111 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
112 bool verify() const { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
113 u_char* c = (u_char*) _guard; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
114 u_char* end = c + GUARD_SIZE; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
115 while (c < end) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
116 if (*c != badResourceValue) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
117 return false; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
118 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
119 c++; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
120 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
121 return true; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
122 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
123 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
124 }; // GuardedMemory::Guard |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
125 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
126 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
127 * Header guard and size |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
128 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
129 class GuardHeader : Guard { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
130 friend class GuardedMemory; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
131 protected: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
132 // Take care in modifying fields here, will effect alignment |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
133 // e.g. x86 ABI 16 byte stack alignment |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
134 union { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
135 uintptr_t __unused_full_word1; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
136 size_t _user_size; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
137 }; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
138 void* _tag; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
139 public: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
140 void set_user_size(const size_t usz) { _user_size = usz; } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
141 size_t get_user_size() const { return _user_size; } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
142 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
143 void set_tag(const void* tag) { _tag = (void*) tag; } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
144 void* get_tag() const { return _tag; } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
145 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
146 }; // GuardedMemory::GuardHeader |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
147 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
148 // Guarded Memory... |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
149 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
150 protected: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
151 u_char* _base_addr; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
152 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
153 public: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
154 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
155 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
156 * Create new guarded memory. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
157 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
158 * Wraps, starting at the given "base_ptr" with guards. Use "get_user_ptr()" |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
159 * to return a pointer suitable for user data. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
160 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
161 * @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
162 * @param user_size the size of the user data to be wrapped. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
163 * @param tag optional general purpose tag. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
164 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
165 GuardedMemory(void* base_ptr, const size_t user_size, const void* tag = NULL) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
166 wrap_with_guards(base_ptr, user_size, tag); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
167 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
168 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
169 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
170 * Wrap existing guarded memory. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
171 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
172 * To use this constructor, one must have created guarded memory with |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
173 * "GuardedMemory(void*, size_t, void*)" (or indirectly via helper, e.g. "wrap_copy()"). |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
174 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
175 * @param user_p existing wrapped memory. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
176 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
177 GuardedMemory(void* userp) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
178 u_char* user_ptr = (u_char*) userp; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
179 assert((uintptr_t)user_ptr > (sizeof(GuardHeader) + 0x1000), "Invalid pointer"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
180 _base_addr = (user_ptr - sizeof(GuardHeader)); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
181 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
182 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
183 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
184 * Create new guarded memory. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
185 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
186 * Wraps, starting at the given "base_ptr" with guards. Allows reuse of stack allocated helper. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
187 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
188 * @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
189 * @param user_size the size of the user data to be wrapped. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
190 * @param tag optional general purpose tag. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
191 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
192 * @return user data pointer (inner pointer to supplied "base_ptr"). |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
193 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
194 void* wrap_with_guards(void* base_ptr, size_t user_size, const void* tag = NULL) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
195 assert(base_ptr != NULL, "Attempt to wrap NULL with memory guard"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
196 _base_addr = (u_char*)base_ptr; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
197 get_head_guard()->build(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
198 get_head_guard()->set_user_size(user_size); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
199 get_tail_guard()->build(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
200 set_tag(tag); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
201 set_user_bytes(uninitBlockPad); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
202 assert(verify_guards(), "Expected valid memory guards"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
203 return get_user_ptr(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
204 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
205 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
206 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
207 * Verify head and tail guards. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
208 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
209 * @return true if guards are intact, false would indicate a buffer overrun. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
210 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
211 bool verify_guards() const { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
212 if (_base_addr != NULL) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
213 return (get_head_guard()->verify() && get_tail_guard()->verify()); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
214 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
215 return false; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
216 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
217 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
218 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
219 * Set the general purpose tag. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
220 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
221 * @param tag general purpose tag. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
222 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
223 void set_tag(const void* tag) { get_head_guard()->set_tag(tag); } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
224 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
225 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
226 * Return the general purpose tag. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
227 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
228 * @return the general purpose tag, defaults to NULL. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
229 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
230 void* get_tag() const { return get_head_guard()->get_tag(); } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
231 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
232 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
233 * Return the size of the user data. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
234 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
235 * @return the size of the user data. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
236 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
237 size_t get_user_size() const { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
238 assert(_base_addr, "Not wrapping any memory"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
239 return get_head_guard()->get_user_size(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
240 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
241 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
242 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
243 * Return the user data pointer. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
244 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
245 * @return the user data pointer. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
246 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
247 u_char* get_user_ptr() const { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
248 assert(_base_addr, "Not wrapping any memory"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
249 return _base_addr + sizeof(GuardHeader); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
250 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
251 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
252 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
253 * Release the wrapped pointer for resource freeing. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
254 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
255 * Pads the user data with "freeBlockPad", and dis-associates the helper. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
256 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
257 * @return the original base pointer used to wrap the data. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
258 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
259 void* release_for_freeing() { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
260 set_user_bytes(freeBlockPad); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
261 return release(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
262 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
263 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
264 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
265 * Dis-associate the help from the original base address. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
266 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
267 * @return the original base pointer used to wrap the data. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
268 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
269 void* release() { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
270 void* p = (void*) _base_addr; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
271 _base_addr = NULL; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
272 return p; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
273 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
274 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
275 virtual void print_on(outputStream* st) const; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
276 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
277 protected: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
278 GuardHeader* get_head_guard() const { return (GuardHeader*) _base_addr; } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
279 Guard* get_tail_guard() const { return (Guard*) (get_user_ptr() + get_user_size()); }; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
280 void set_user_bytes(u_char ch) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
281 memset(get_user_ptr(), ch, get_user_size()); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
282 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
283 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
284 public: |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
285 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
286 * Return the total size required for wrapping the given user size. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
287 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
288 * @return the total size required for wrapping the given user size. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
289 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
290 static size_t get_total_size(size_t user_size) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
291 size_t total_size = sizeof(GuardHeader) + user_size + sizeof(Guard); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
292 assert(total_size > user_size, "Unexpected wrap-around"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
293 return total_size; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
294 } |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
295 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
296 // Helper functions... |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
297 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
298 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
299 * Wrap a copy of size "len" of "ptr". |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
300 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
301 * @param ptr the memory to be copied |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
302 * @param len the length of the copy |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
303 * @param tag optional general purpose tag (see GuardedMemory::get_tag()) |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
304 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
305 * @return guarded wrapped memory pointer to the user area, or NULL if OOM. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
306 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
307 static void* wrap_copy(const void* p, const size_t len, const void* tag = NULL); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
308 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
309 /** |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
310 * Free wrapped copy. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
311 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
312 * Frees memory copied with "wrap_copy()". |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
313 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
314 * @param p memory returned by "wrap_copy()". |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
315 * |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
316 * @return true if guards were verified as intact. false indicates a buffer overrun. |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
317 */ |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
318 static bool free_copy(void* p); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
319 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
320 // Testing... |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
321 #ifndef PRODUCT |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
322 static void test_guarded_memory(void); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
323 #endif |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
324 }; // GuardedMemory |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
325 |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
326 #endif // SHARE_VM_MEMORY_GUARDED_MEMORY_HPP |