Mercurial > hg > graal-jvmci-8
comparison src/share/vm/utilities/quickSort.cpp @ 10271:f9be75d21404
8012902: remove use of global operator new - take 2
Summary: The fix of 8010992, disable use of global operator new and new[] which caused failure on some tests. This takes two of the bugs also add ALLOW_OPERATOR_NEW_USAGE to prevent crash for third party code calling operator new of jvm on certain platforms.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@oracle.com
author | minqi |
---|---|
date | Tue, 14 May 2013 09:41:12 -0700 |
parents | 5a9fa2ba85f0 |
children | e484fe2abebd |
comparison
equal
deleted
inserted
replaced
10269:a9270d9ecb13 | 10271:f9be75d21404 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
28 | 28 |
29 #ifndef PRODUCT | 29 #ifndef PRODUCT |
30 | 30 |
31 #include "runtime/os.hpp" | 31 #include "runtime/os.hpp" |
32 #include "utilities/quickSort.hpp" | 32 #include "utilities/quickSort.hpp" |
33 #include "memory/allocation.hpp" | |
34 #include "memory/allocation.inline.hpp" | |
33 #include <stdlib.h> | 35 #include <stdlib.h> |
34 | 36 |
35 static int test_comparator(int a, int b) { | 37 static int test_comparator(int a, int b) { |
36 if (a == b) { | 38 if (a == b) { |
37 return 0; | 39 return 0; |
185 } | 187 } |
186 | 188 |
187 // test sorting random arrays | 189 // test sorting random arrays |
188 for (int i = 0; i < 1000; i++) { | 190 for (int i = 0; i < 1000; i++) { |
189 int length = os::random() % 100; | 191 int length = os::random() % 100; |
190 int* test_array = new int[length]; | 192 int* test_array = NEW_C_HEAP_ARRAY(int, length, mtInternal); |
191 int* expected_array = new int[length]; | 193 int* expected_array = NEW_C_HEAP_ARRAY(int, length, mtInternal); |
192 for (int j = 0; j < length; j++) { | 194 for (int j = 0; j < length; j++) { |
193 // Choose random values, but get a chance of getting duplicates | 195 // Choose random values, but get a chance of getting duplicates |
194 test_array[j] = os::random() % (length * 2); | 196 test_array[j] = os::random() % (length * 2); |
195 expected_array[j] = test_array[j]; | 197 expected_array[j] = test_array[j]; |
196 } | 198 } |
208 sort(test_array, length, test_even_odd_comparator, true); | 210 sort(test_array, length, test_even_odd_comparator, true); |
209 assert(compare_arrays(test_array, expected_array, length), "Sorting identical arrays rendered different results"); | 211 assert(compare_arrays(test_array, expected_array, length), "Sorting identical arrays rendered different results"); |
210 sort(test_array, length, test_even_odd_comparator, true); | 212 sort(test_array, length, test_even_odd_comparator, true); |
211 assert(compare_arrays(test_array, expected_array, length), "Sorting already sorted array changed order of elements - not idempotent"); | 213 assert(compare_arrays(test_array, expected_array, length), "Sorting already sorted array changed order of elements - not idempotent"); |
212 | 214 |
213 delete[] test_array; | 215 FREE_C_HEAP_ARRAY(int, test_array, mtInternal); |
214 delete[] expected_array; | 216 FREE_C_HEAP_ARRAY(int, expected_array, mtInternal); |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 #endif | 220 #endif |