129
130 #ifndef PRODUCT
131 // Forward declaration
132 void TestReservedSpace_test();
133 void TestReserveMemorySpecial_test();
134 void TestVirtualSpace_test();
135 void TestMetaspaceAux_test();
136 #endif
137
138 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
139 #ifndef PRODUCT
140 TestReservedSpace_test();
141 TestReserveMemorySpecial_test();
142 TestVirtualSpace_test();
143 TestMetaspaceAux_test();
144 #endif
145 WB_END
146
147 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
148 size_t granularity = os::vm_allocation_granularity();
149 ReservedHeapSpace rhs(100 * granularity, granularity, false, NULL);
150 VirtualSpace vs;
151 vs.initialize(rhs, 50 * granularity);
152
153 //Check if constraints are complied
154 if (!( UseCompressedOops && rhs.base() != NULL &&
155 Universe::narrow_oop_base() != NULL &&
156 Universe::narrow_oop_use_implicit_null_checks() )) {
157 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
158 "\tUseCompressedOops is %d\n"
159 "\trhs.base() is "PTR_FORMAT"\n"
160 "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n"
161 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
162 UseCompressedOops,
163 rhs.base(),
164 Universe::narrow_oop_base(),
165 Universe::narrow_oop_use_implicit_null_checks());
166 return;
167 }
168 tty->print_cr("Reading from no access area... ");
169 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
170 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
171 WB_END
172
173 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
174 size_t magnitude, size_t iterations) {
175 size_t granularity = os::vm_allocation_granularity();
176 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false, NULL);
177 VirtualSpace vs;
178 if (!vs.initialize(rhs, 0)) {
179 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
180 return 3;
181 }
182
183 long seed = os::random();
184 tty->print_cr("Random seed is %ld", seed);
185 os::init_random(seed);
186
187 for (size_t i = 0; i < iterations; i++) {
188
189 // Whether we will shrink or grow
190 bool shrink = os::random() % 2L == 0;
191
192 // Get random delta to resize virtual space
193 size_t delta = (size_t)os::random() % magnitude;
194
195 // If we are about to shrink virtual space below zero, then expand instead
196 if (shrink && vs.committed_size() < delta) {
|
129
130 #ifndef PRODUCT
131 // Forward declaration
132 void TestReservedSpace_test();
133 void TestReserveMemorySpecial_test();
134 void TestVirtualSpace_test();
135 void TestMetaspaceAux_test();
136 #endif
137
138 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
139 #ifndef PRODUCT
140 TestReservedSpace_test();
141 TestReserveMemorySpecial_test();
142 TestVirtualSpace_test();
143 TestMetaspaceAux_test();
144 #endif
145 WB_END
146
147 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
148 size_t granularity = os::vm_allocation_granularity();
149 ReservedHeapSpace rhs(100 * granularity, granularity, false);
150 VirtualSpace vs;
151 vs.initialize(rhs, 50 * granularity);
152
153 // Check if constraints are complied
154 if (!( UseCompressedOops && rhs.base() != NULL &&
155 Universe::narrow_oop_base() != NULL &&
156 Universe::narrow_oop_use_implicit_null_checks() )) {
157 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
158 "\tUseCompressedOops is %d\n"
159 "\trhs.base() is "PTR_FORMAT"\n"
160 "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n"
161 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
162 UseCompressedOops,
163 rhs.base(),
164 Universe::narrow_oop_base(),
165 Universe::narrow_oop_use_implicit_null_checks());
166 return;
167 }
168 tty->print_cr("Reading from no access area... ");
169 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
170 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
171 WB_END
172
173 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
174 size_t magnitude, size_t iterations) {
175 size_t granularity = os::vm_allocation_granularity();
176 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false);
177 VirtualSpace vs;
178 if (!vs.initialize(rhs, 0)) {
179 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
180 return 3;
181 }
182
183 long seed = os::random();
184 tty->print_cr("Random seed is %ld", seed);
185 os::init_random(seed);
186
187 for (size_t i = 0; i < iterations; i++) {
188
189 // Whether we will shrink or grow
190 bool shrink = os::random() % 2L == 0;
191
192 // Get random delta to resize virtual space
193 size_t delta = (size_t)os::random() % magnitude;
194
195 // If we are about to shrink virtual space below zero, then expand instead
196 if (shrink && vs.committed_size() < delta) {
|