Skip to content

Commit 9ad9228

Browse files
committed
8296956: [JVMCI] HotSpotResolvedJavaFieldImpl.getIndex returns wrong value
Reviewed-by: adinn Backport-of: 95c390ec75eec31cdf613c8bb236e43aa65a1bb5
1 parent 8674e7c commit 9ad9228

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package jdk.vm.ci.hotspot;
25+
26+
import jdk.vm.ci.meta.JavaType;
27+
import jdk.vm.ci.meta.ResolvedJavaField;
28+
29+
public class HotSpotResolvedJavaFieldHelper {
30+
public static ResolvedJavaField createField(HotSpotResolvedObjectTypeImpl holder, JavaType type, int offset, int modifiers, int index) {
31+
return new HotSpotResolvedJavaFieldImpl(holder, type, offset, modifiers, index);
32+
}
33+
34+
public static int getIndex(ResolvedJavaField field) {
35+
return ((HotSpotResolvedJavaFieldImpl) field).getIndex();
36+
}
37+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @requires vm.jvmci
27+
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
28+
* jdk.internal.vm.ci/jdk.vm.ci.meta
29+
* @library /compiler/jvmci/common/patches
30+
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldHelper
31+
* @run testng/othervm
32+
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler
33+
* jdk.vm.ci.hotspot.test.TestHotSpotResolvedJavaField
34+
*/
35+
36+
package jdk.vm.ci.hotspot.test;
37+
38+
import org.testng.Assert;
39+
import org.testng.annotations.Test;
40+
41+
import jdk.vm.ci.hotspot.HotSpotResolvedJavaFieldHelper;
42+
import jdk.vm.ci.meta.ResolvedJavaField;
43+
44+
public class TestHotSpotResolvedJavaField {
45+
46+
@Test
47+
public void testIndex() {
48+
int max = Character.MAX_VALUE;
49+
int[] valid = {0, 1, max - 1, max};
50+
for (int index : valid) {
51+
ResolvedJavaField field = HotSpotResolvedJavaFieldHelper.createField(null, null, 0, 0, index);
52+
Assert.assertEquals(HotSpotResolvedJavaFieldHelper.getIndex(field), index);
53+
}
54+
}
55+
56+
@Test
57+
public void testOffset() {
58+
int min = Integer.MIN_VALUE;
59+
int max = Integer.MAX_VALUE;
60+
int[] valid = {min, min + 1, -2, 0, 1, max - 1, max};
61+
for (int offset : valid) {
62+
ResolvedJavaField field = HotSpotResolvedJavaFieldHelper.createField(null, null, offset, 0, 0);
63+
Assert.assertEquals(field.getOffset(), offset);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)