|
1 | | -///* |
2 | | -// * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | | -// * Copyright (c) 2021, 2022, Red Hat Inc. All rights reserved. |
4 | | -// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 | | -// * |
6 | | -// * This code is free software; you can redistribute it and/or modify it |
7 | | -// * under the terms of the GNU General Public License version 2 only, as |
8 | | -// * published by the Free Software Foundation. Oracle designates this |
9 | | -// * particular file as subject to the "Classpath" exception as provided |
10 | | -// * by Oracle in the LICENSE file that accompanied this code. |
11 | | -// * |
12 | | -// * This code is distributed in the hope that it will be useful, but WITHOUT |
13 | | -// * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | | -// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | | -// * version 2 for more details (a copy is included in the LICENSE file that |
16 | | -// * accompanied this code). |
17 | | -// * |
18 | | -// * You should have received a copy of the GNU General Public License version |
19 | | -// * 2 along with this work; if not, write to the Free Software Foundation, |
20 | | -// * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
21 | | -// * |
22 | | -// * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
23 | | -// * or visit www.oracle.com if you need additional information or have any |
24 | | -// * questions. |
25 | | -// */ |
26 | | -// |
27 | | -//package com.oracle.svm.test.jfr; |
28 | | -// |
29 | | -//import com.oracle.svm.test.jfr.events.ClassEvent; |
30 | | -//import jdk.jfr.Recording; |
31 | | -//import jdk.jfr.consumer.RecordedEvent; |
32 | | -//import org.junit.Test; |
33 | | -// |
34 | | -//import java.util.List; |
35 | | -// |
36 | | -//import com.oracle.svm.core.SubstrateUtil; |
37 | | -//import com.oracle.svm.core.headers.LibC; |
38 | | -//import com.oracle.svm.core.nmt.NmtCategory; |
39 | | -//import com.oracle.svm.core.posix.headers.Dirent; |
40 | | -//import com.oracle.svm.core.posix.headers.Errno; |
41 | | -//import com.oracle.svm.core.posix.headers.Fcntl; |
42 | | -//import com.oracle.svm.core.posix.headers.Unistd; |
43 | | -//import org.graalvm.word.Pointer; |
44 | | -//import jdk.graal.compiler.word.Word; |
45 | | -//import org.graalvm.word.WordFactory; |
46 | | -////import jdk.jfr.internal.LogLevel; |
47 | | -////import jdk.jfr.internal.LogTag; |
48 | | -////import jdk.jfr.internal.Logger; |
49 | | -//import org.graalvm.nativeimage.c.type.CCharPointer; |
50 | | -//import org.graalvm.nativeimage.ImageSingletons; |
51 | | -//import org.graalvm.nativeimage.Platform; |
52 | | -//import org.graalvm.nativeimage.Platforms; |
53 | | -//import org.graalvm.nativeimage.StackValue; |
54 | | -// |
55 | | -//import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; |
56 | | -//import com.oracle.svm.core.Uninterruptible; |
57 | | -//import com.oracle.svm.core.jfr.JfrEmergencyDumpFeature; |
58 | | -//import com.oracle.svm.core.jfr.JfrEmergencyDumpSupport; |
59 | | -//import com.oracle.svm.core.memory.NativeMemory; |
60 | | -//import com.oracle.svm.core.memory.NullableNativeMemory; |
61 | | -//import com.oracle.svm.core.os.RawFileOperationSupport; |
62 | | -//import com.oracle.svm.core.os.RawFileOperationSupport.FileAccessMode; |
63 | | -//import com.oracle.svm.core.os.RawFileOperationSupport.FileCreationMode; |
64 | | -//import com.oracle.svm.core.os.RawFileOperationSupport.RawFileDescriptor; |
65 | | -//import com.oracle.svm.core.util.BasedOnJDKFile; |
66 | | -//import com.oracle.svm.core.collections.GrowableWordArray; |
67 | | -//import com.oracle.svm.core.collections.GrowableWordArrayAccess; |
68 | | -// |
69 | | -//import jdk.graal.compiler.api.replacements.Fold; |
70 | | -// |
71 | | -//import java.nio.charset.StandardCharsets; |
72 | | -// |
73 | | -//import static com.oracle.svm.core.posix.headers.Fcntl.O_NOFOLLOW; |
74 | | -//import static com.oracle.svm.core.posix.headers.Fcntl.O_RDONLY; |
75 | | -// |
76 | | -//import static org.junit.Assert.assertEquals; |
77 | | -// |
78 | | -//public class TestGrowableWordArrayQuickSort { |
79 | | -// @Test |
80 | | -// public void test() throws Throwable { |
81 | | -// GrowableWordArray gwa = StackValue.get(GrowableWordArray.class); |
82 | | -// GrowableWordArrayAccess.initialize(gwa); |
83 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(3), NmtCategory.JFR); |
84 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(1), NmtCategory.JFR); |
85 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(5), NmtCategory.JFR); |
86 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(4), NmtCategory.JFR); |
87 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(2), NmtCategory.JFR); |
88 | | -// GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(4), NmtCategory.JFR); |
89 | | -// qsort(gwa, 0,5); |
90 | | -// for (int i=0; i < 6; i ++){ |
91 | | -// System.out.println(GrowableWordArrayAccess.read(gwa, i).rawValue()); |
92 | | -// } |
93 | | -// } |
94 | | -// |
95 | | -// private static void qsort(GrowableWordArray gwa, int low, int high) { |
96 | | -// if (low < high) { |
97 | | -// int pivotIndex = partition(gwa, low, high); |
98 | | -// |
99 | | -// qsort(gwa, low, pivotIndex - 1); |
100 | | -// qsort(gwa, pivotIndex + 1, high); |
101 | | -// } |
102 | | -// } |
103 | | -// |
104 | | -// private static int partition(GrowableWordArray gwa, int low, int high) { |
105 | | -// // Choose the last element as pivot |
106 | | -// CCharPointer pivot = GrowableWordArrayAccess.read(gwa, high); |
107 | | -// |
108 | | -// // Pointer for the greater element |
109 | | -// int i = low - 1; |
110 | | -// |
111 | | -// // Traverse through all elements |
112 | | -// // If element is smaller than or equal to pivot, swap it |
113 | | -// for (int j = low; j < high; j++) { |
114 | | -// if (compare(GrowableWordArrayAccess.read(gwa, j), pivot)) { |
115 | | -// i++; |
116 | | -// |
117 | | -// // Swap elements at i and j |
118 | | -// CCharPointer temp = GrowableWordArrayAccess.read(gwa, i); |
119 | | -// GrowableWordArrayAccess.write(gwa,i, GrowableWordArrayAccess.read(gwa, j)); |
120 | | -// GrowableWordArrayAccess.write(gwa, j, temp); |
121 | | -// } |
122 | | -// } |
123 | | -// |
124 | | -// // Swap the pivot element with the element at i+1 |
125 | | -// CCharPointer temp = GrowableWordArrayAccess.read(gwa, i + 1); |
126 | | -// GrowableWordArrayAccess.write(gwa, i + 1, GrowableWordArrayAccess.read(gwa, high)); |
127 | | -// GrowableWordArrayAccess.write(gwa, high, temp); |
128 | | -// |
129 | | -// // Return the partition index |
130 | | -// return i + 1; |
131 | | -// } |
132 | | -// |
133 | | -//// static boolean compare(CCharPointer a, CCharPointer b) { |
134 | | -//// // Use strcmp(CCharPointer s1, CCharPointer s2) and strchr(CCharPointer str, int c) |
135 | | -//// |
136 | | -//// return a.read() <= b.read(); |
137 | | -//// } |
138 | | -// |
139 | | -// static boolean compare(CCharPointer a, CCharPointer b) { |
140 | | -// // Use strcmp(CCharPointer s1, CCharPointer s2) and strchr(CCharPointer str, int c) |
141 | | -// |
142 | | -// return a.rawValue() <= b.rawValue(); |
143 | | -// } |
144 | | -// |
145 | | -//} |
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2025, 2025, Red Hat Inc. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. Oracle designates this |
| 9 | + * particular file as subject to the "Classpath" exception as provided |
| 10 | + * by Oracle in the LICENSE file that accompanied this code. |
| 11 | + * |
| 12 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 16 | + * accompanied this code). |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License version |
| 19 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + * |
| 22 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | + * or visit www.oracle.com if you need additional information or have any |
| 24 | + * questions. |
| 25 | + */ |
| 26 | + |
| 27 | +package com.oracle.svm.test.jfr; |
| 28 | + |
| 29 | +import org.junit.Test; |
| 30 | + |
| 31 | +import com.oracle.svm.core.nmt.NmtCategory; |
| 32 | +import jdk.graal.compiler.word.Word; |
| 33 | +import org.graalvm.word.WordFactory; |
| 34 | +import org.graalvm.nativeimage.StackValue; |
| 35 | + |
| 36 | +import com.oracle.svm.core.collections.GrowableWordArray; |
| 37 | +import com.oracle.svm.core.collections.GrowableWordArrayAccess; |
| 38 | + |
| 39 | +import static org.junit.Assert.assertTrue; |
| 40 | + |
| 41 | +public class TestGrowableWordArrayQuickSort { |
| 42 | + @Test |
| 43 | + public void test() throws Throwable { |
| 44 | + GrowableWordArray gwa = StackValue.get(GrowableWordArray.class); |
| 45 | + GrowableWordArrayAccess.initialize(gwa); |
| 46 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(3), NmtCategory.JFR); |
| 47 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(1), NmtCategory.JFR); |
| 48 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(5), NmtCategory.JFR); |
| 49 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(4), NmtCategory.JFR); |
| 50 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(2), NmtCategory.JFR); |
| 51 | + GrowableWordArrayAccess.add(gwa, WordFactory.unsigned(4), NmtCategory.JFR); |
| 52 | + GrowableWordArrayAccess.qsort(gwa, 0, gwa.getSize() - 1, TestGrowableWordArrayQuickSort::compare); |
| 53 | + long last = 0; |
| 54 | + for (int i = 0; i < gwa.getSize(); i++) { |
| 55 | + long current = GrowableWordArrayAccess.read(gwa, i).rawValue(); |
| 56 | + assertTrue(last <= current); |
| 57 | + last = current; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + static int compare(Word a, Word b) { |
| 62 | + if (a.rawValue() < b.rawValue()) { |
| 63 | + return -1; |
| 64 | + } else if (a.rawValue() == b.rawValue()) { |
| 65 | + return 0; |
| 66 | + } else { |
| 67 | + return 1; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments