author | david |
Tue, 29 Sep 2015 11:02:08 +0200 | |
changeset 33105 | 294e48b4f704 |
parent 25056 | 5ad92b0d1beb |
child 35529 | 39376b4613b5 |
permissions | -rw-r--r-- |
25056
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
1 |
/* |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
4 |
* |
5ad92b0d1beb
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 |
5ad92b0d1beb
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 |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
8 |
* |
5ad92b0d1beb
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 |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5ad92b0d1beb
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 |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
13 |
* accompanied this code). |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
14 |
* |
5ad92b0d1beb
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 |
5ad92b0d1beb
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, |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
18 |
* |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5ad92b0d1beb
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 |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
21 |
* questions. |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
22 |
* |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
23 |
*/ |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
25 |
#include "memory/allocation.hpp" |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
26 |
#include "memory/allocation.inline.hpp" |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
27 |
#include "memory/guardedMemory.hpp" |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
28 |
#include "runtime/os.hpp" |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
29 |
|
5ad92b0d1beb
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) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
31 |
size_t total_sz = GuardedMemory::get_total_size(len); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
32 |
void* outerp = os::malloc(total_sz, mtInternal); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
33 |
if (outerp != NULL) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
34 |
GuardedMemory guarded(outerp, len, tag); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
35 |
void* innerp = guarded.get_user_ptr(); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
36 |
memcpy(innerp, ptr, len); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
37 |
return innerp; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
38 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
39 |
return NULL; // OOM |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
40 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
41 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
42 |
bool GuardedMemory::free_copy(void* p) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
43 |
if (p == NULL) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
44 |
return true; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
45 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
46 |
GuardedMemory guarded((u_char*)p); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
47 |
bool verify_ok = guarded.verify_guards(); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
48 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
49 |
/* always attempt to free, pass problem on to any nested memchecker */ |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
50 |
os::free(guarded.release_for_freeing()); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
51 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
52 |
return verify_ok; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
53 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
54 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
55 |
void GuardedMemory::print_on(outputStream* st) const { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
56 |
if (_base_addr == NULL) { |
5ad92b0d1beb
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)); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
58 |
return; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
59 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
60 |
st->print_cr("GuardedMemory(" PTR_FORMAT ") base_addr=" PTR_FORMAT |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
61 |
" tag=" PTR_FORMAT " user_size=" SIZE_FORMAT " user_data=" PTR_FORMAT, |
5ad92b0d1beb
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())); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
63 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
64 |
Guard* guard = get_head_guard(); |
5ad92b0d1beb
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")); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
66 |
guard = get_tail_guard(); |
5ad92b0d1beb
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")); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
68 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
69 |
u_char udata = *get_user_ptr(); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
70 |
switch (udata) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
71 |
case uninitBlockPad: |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
72 |
st->print_cr(" User data appears unused"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
73 |
break; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
74 |
case freeBlockPad: |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
75 |
st->print_cr(" User data appears to have been freed"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
76 |
break; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
77 |
default: |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
78 |
st->print_cr(" User data appears to be in use"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
79 |
break; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
80 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
81 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
82 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
83 |
// test code... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
84 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
85 |
#ifndef PRODUCT |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
86 |
|
5ad92b0d1beb
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) { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
88 |
assert(p != NULL, "NULL pointer given to check"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
89 |
u_char* c = (u_char*) p; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
90 |
GuardedMemory guarded(c); |
5ad92b0d1beb
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"); |
5ad92b0d1beb
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"); |
5ad92b0d1beb
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"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
94 |
assert(guarded.verify_guards(), "Guard broken"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
95 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
96 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
97 |
void GuardedMemory::test_guarded_memory() { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
98 |
// Test the basic characteristics... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
99 |
size_t total_sz = GuardedMemory::get_total_size(1); |
5ad92b0d1beb
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"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
101 |
u_char* basep = (u_char*) os::malloc(total_sz, mtInternal); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
102 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
103 |
GuardedMemory guarded(basep, 1, (void*)0xf000f000); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
104 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
105 |
assert(*basep == badResourceValue, "Expected guard in the form of badResourceValue"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
106 |
u_char* userp = guarded.get_user_ptr(); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
107 |
assert(*userp == uninitBlockPad, "Expected uninitialized data in the form of uninitBlockPad"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
108 |
guarded_memory_test_check(userp, 1, (void*)0xf000f000); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
109 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
110 |
void* freep = guarded.release_for_freeing(); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
111 |
assert((u_char*)freep == basep, "Expected the same pointer guard was "); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
112 |
assert(*userp == freeBlockPad, "Expected user data to be free block padded"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
113 |
assert(!guarded.verify_guards(), "Expected failed"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
114 |
os::free(freep); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
115 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
116 |
// Test a number of odd sizes... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
117 |
size_t sz = 0; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
118 |
do { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
119 |
void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
120 |
void* up = guarded.wrap_with_guards(p, sz, (void*)1); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
121 |
memset(up, 0, sz); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
122 |
guarded_memory_test_check(up, sz, (void*)1); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
123 |
os::free(guarded.release_for_freeing()); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
124 |
sz = (sz << 4) + 1; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
125 |
} while (sz < (256 * 1024)); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
126 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
127 |
// Test buffer overrun into head... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
128 |
basep = (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
129 |
guarded.wrap_with_guards(basep, 1); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
130 |
*basep = 0; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
131 |
assert(!guarded.verify_guards(), "Expected failure"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
132 |
os::free(basep); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
133 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
134 |
// Test buffer overrun into tail with a number of odd sizes... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
135 |
sz = 1; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
136 |
do { |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
137 |
void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
138 |
void* up = guarded.wrap_with_guards(p, sz, (void*)1); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
139 |
memset(up, 0, sz + 1); // Buffer-overwrite (within guard) |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
140 |
assert(!guarded.verify_guards(), "Guard was not broken as expected"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
141 |
os::free(guarded.release_for_freeing()); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
142 |
sz = (sz << 4) + 1; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
143 |
} while (sz < (256 * 1024)); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
144 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
145 |
// Test wrap_copy/wrap_free... |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
146 |
assert(GuardedMemory::free_copy(NULL), "Expected free NULL to be OK"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
147 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
148 |
const char* str = "Check my bounds out"; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
149 |
size_t str_sz = strlen(str) + 1; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
150 |
char* str_copy = (char*) GuardedMemory::wrap_copy(str, str_sz); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
151 |
guarded_memory_test_check(str_copy, str_sz, NULL); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
152 |
assert(strcmp(str, str_copy) == 0, "Not identical copy"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
153 |
assert(GuardedMemory::free_copy(str_copy), "Free copy failed to verify"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
154 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
155 |
void* no_data = NULL; |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
156 |
void* no_data_copy = GuardedMemory::wrap_copy(no_data, 0); |
5ad92b0d1beb
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"); |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
158 |
} |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
159 |
|
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
160 |
#endif // !PRODUCT |
5ad92b0d1beb
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
diff
changeset
|
161 |