Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/lockWordAlignment/src/main.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
import sun.misc.Unsafe;
24
25
class main {
26
27
public static void main(String[] args) throws Throwable {
28
Unsafe u = Unsafe.getUnsafe();
29
long offset;
30
31
Class cl = Class.forName(args[0]);
32
33
int alignment = com.ibm.oti.vm.VM.FJ9OBJECT_SIZE;
34
35
try {
36
offset = u.objectFieldOffset(cl.getDeclaredField("i"));
37
System.out.println(offset);
38
if (offset % 4 != 0) {
39
System.out.println("error: int is not aligned");
40
}
41
} catch (Exception e) {
42
43
}
44
45
try {
46
offset = u.objectFieldOffset(cl.getDeclaredField("l"));
47
System.out.println(offset);
48
if (offset % 8 != 0) {
49
System.out.println("error: long is not aligned");
50
}
51
} catch (Exception e) {
52
53
}
54
55
try {
56
offset = u.objectFieldOffset(cl.getDeclaredField("o"));
57
System.out.println(offset);
58
if (offset % alignment != 0) {
59
System.out.println("error: object is not aligned");
60
}
61
} catch (Exception e) {
62
63
}
64
65
try {
66
offset = u.objectFieldOffset(cl.getDeclaredField("d"));
67
System.out.println(offset);
68
if (offset % 8 != 0) {
69
System.out.println("error: double is not aligned");
70
}
71
} catch (Exception e) {
72
73
}
74
}
75
}
76
77