annotate src/share/vm/memory/guardedMemory.cpp @ 20318:fa62fb12cdca

6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical. Summary: Wrapped memory with standard bounds checking "GuardedMemory". Reviewed-by: zgu, fparain, dcubed
author dsimms
date Thu, 14 Aug 2014 15:16:07 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "precompiled.hpp"
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
25 #include "memory/allocation.hpp"
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
26 #include "memory/allocation.inline.hpp"
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
27 #include "memory/guardedMemory.hpp"
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
28 #include "runtime/os.hpp"
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
29
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
30 void* GuardedMemory::wrap_copy(const void* ptr, const size_t len, const void* tag) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
31 size_t total_sz = GuardedMemory::get_total_size(len);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
32 void* outerp = os::malloc(total_sz, mtInternal);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
33 if (outerp != NULL) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
34 GuardedMemory guarded(outerp, len, tag);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
35 void* innerp = guarded.get_user_ptr();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
36 memcpy(innerp, ptr, len);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
37 return innerp;
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 return NULL; // OOM
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
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
42 bool GuardedMemory::free_copy(void* p) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
43 if (p == NULL) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
44 return true;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
45 }
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
46 GuardedMemory guarded((u_char*)p);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
47 bool verify_ok = guarded.verify_guards();
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 /* always attempt to free, pass problem on to any nested memchecker */
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
50 os::free(guarded.release_for_freeing());
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
51
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
52 return verify_ok;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
53 }
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
54
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
55 void GuardedMemory::print_on(outputStream* st) const {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
56 if (_base_addr == NULL) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
57 st->print_cr("GuardedMemory(" PTR_FORMAT ") not associated to any memory", p2i(this));
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
58 return;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
59 }
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
60 st->print_cr("GuardedMemory(" PTR_FORMAT ") base_addr=" PTR_FORMAT
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
61 " tag=" PTR_FORMAT " user_size=" SIZE_FORMAT " user_data=" PTR_FORMAT,
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
62 p2i(this), p2i(_base_addr), p2i(get_tag()), get_user_size(), p2i(get_user_ptr()));
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
63
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
64 Guard* guard = get_head_guard();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
65 st->print_cr(" Header guard @" PTR_FORMAT " is %s", p2i(guard), (guard->verify() ? "OK" : "BROKEN"));
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
66 guard = get_tail_guard();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
67 st->print_cr(" Trailer guard @" PTR_FORMAT " is %s", p2i(guard), (guard->verify() ? "OK" : "BROKEN"));
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
68
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
69 u_char udata = *get_user_ptr();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
70 switch (udata) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
71 case uninitBlockPad:
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
72 st->print_cr(" User data appears unused");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
73 break;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
74 case freeBlockPad:
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
75 st->print_cr(" User data appears to have been freed");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
76 break;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
77 default:
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
78 st->print_cr(" User data appears to be in use");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
79 break;
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 }
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 // test code...
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 #ifndef PRODUCT
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 static void guarded_memory_test_check(void* p, size_t sz, void* tag) {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
88 assert(p != NULL, "NULL pointer given to check");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
89 u_char* c = (u_char*) p;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
90 GuardedMemory guarded(c);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
91 assert(guarded.get_tag() == tag, "Tag is not the same as supplied");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
92 assert(guarded.get_user_ptr() == c, "User pointer is not the same as supplied");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
93 assert(guarded.get_user_size() == sz, "User size is not the same as supplied");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
94 assert(guarded.verify_guards(), "Guard broken");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
95 }
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
96
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
97 void GuardedMemory::test_guarded_memory() {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
98 // Test the basic characteristics...
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
99 size_t total_sz = GuardedMemory::get_total_size(1);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
100 assert(total_sz > 1 && total_sz >= (sizeof(GuardHeader) + 1 + sizeof(Guard)), "Unexpected size");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
101 u_char* basep = (u_char*) os::malloc(total_sz, mtInternal);
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 GuardedMemory guarded(basep, 1, (void*)0xf000f000);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
104
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
105 assert(*basep == badResourceValue, "Expected guard in the form of badResourceValue");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
106 u_char* userp = guarded.get_user_ptr();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
107 assert(*userp == uninitBlockPad, "Expected uninitialized data in the form of uninitBlockPad");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
108 guarded_memory_test_check(userp, 1, (void*)0xf000f000);
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 void* freep = guarded.release_for_freeing();
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
111 assert((u_char*)freep == basep, "Expected the same pointer guard was ");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
112 assert(*userp == freeBlockPad, "Expected user data to be free block padded");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
113 assert(!guarded.verify_guards(), "Expected failed");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
114 os::free(freep);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
115
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
116 // Test a number of odd sizes...
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
117 size_t sz = 0;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
118 do {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
119 void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
120 void* up = guarded.wrap_with_guards(p, sz, (void*)1);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
121 memset(up, 0, sz);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
122 guarded_memory_test_check(up, sz, (void*)1);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
123 os::free(guarded.release_for_freeing());
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
124 sz = (sz << 4) + 1;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
125 } while (sz < (256 * 1024));
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 // Test buffer overrun into head...
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
128 basep = (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
129 guarded.wrap_with_guards(basep, 1);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
130 *basep = 0;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
131 assert(!guarded.verify_guards(), "Expected failure");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
132 os::free(basep);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
133
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
134 // Test buffer overrun into tail with a number of odd sizes...
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
135 sz = 1;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
136 do {
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
137 void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
138 void* up = guarded.wrap_with_guards(p, sz, (void*)1);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
139 memset(up, 0, sz + 1); // Buffer-overwrite (within guard)
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
140 assert(!guarded.verify_guards(), "Guard was not broken as expected");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
141 os::free(guarded.release_for_freeing());
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
142 sz = (sz << 4) + 1;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
143 } while (sz < (256 * 1024));
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
144
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
145 // Test wrap_copy/wrap_free...
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
146 assert(GuardedMemory::free_copy(NULL), "Expected free NULL to be OK");
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 const char* str = "Check my bounds out";
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
149 size_t str_sz = strlen(str) + 1;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
150 char* str_copy = (char*) GuardedMemory::wrap_copy(str, str_sz);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
151 guarded_memory_test_check(str_copy, str_sz, NULL);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
152 assert(strcmp(str, str_copy) == 0, "Not identical copy");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
153 assert(GuardedMemory::free_copy(str_copy), "Free copy failed to verify");
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 void* no_data = NULL;
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
156 void* no_data_copy = GuardedMemory::wrap_copy(no_data, 0);
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
157 assert(GuardedMemory::free_copy(no_data_copy), "Expected valid guards even for no data copy");
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
158 }
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
159
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
160 #endif // !PRODUCT
fa62fb12cdca 6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff changeset
161