1 /*
2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3  * Copyright (c) 2019, 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 jdk.internal.misc;
28 
29 // Android-added: Android-specific implNote.
30 /**
31  * A class used to expose details of the underlying hardware that
32  * configure the operation of class Unsafe.  This class is
33  * package-private as the only intended client is class Unsafe.
34  * All fields in this class must be static final constants.
35  *
36  * @since 13
37  *
38  * @implNote
39  *
40  * The JVM injects hardware-specific values into all the static fields
41  * of this class during JVM initialization. The static initialization
42  * block is executed when the class is initialized then JVM injection
43  * updates the fields with the correct constants. The static block
44  * is required to prevent the fields from being considered constant
45  * variables, so the field values will be not be compiled directly into
46  * any class that uses them.
47  *
48  * @implNote
49  *
50  * On Android the VM does not inject the values, they are rather set as needed from the static
51  * block.
52  */
53 
54 final class UnsafeConstants {
55 
56     /**
57      * This constructor is private because the class is not meant to
58      * be instantiated.
59      */
UnsafeConstants()60     private UnsafeConstants() {}
61 
62     // BEGIN Android-removed: Retrieved through Unsafe.addressSize().
63     /*
64     /**
65      * The size in bytes of a native pointer, as stored via {@link
66      * #putAddress}.  This value will be either 4 or 8.  Note that the
67      * sizes of other primitive types (as stored in native memory
68      * blocks) is determined fully by their information content.
69      *
70      * @implNote
71      * The actual value for this field is injected by the JVM.
72      * /
73 
74     static final int ADDRESS_SIZE0;
75      */
76     // END Android-removed: Retrieved through Unsafe.addressSize().
77 
78     // BEGIN Android-removed: Retrieved through Unsafe.pageSize().
79     /*
80     /**
81      * The size in bytes of a native memory page (whatever that is).
82      * This value will always be a power of two.
83      *
84      * @implNote
85      * The actual value for this field is injected by the JVM.
86      * /
87 
88     static final int PAGE_SIZE;
89      */
90     // END Android-removed: Retrieved through Unsafe.pageSize().
91 
92     /**
93      * Flag whose value is true if and only if the native endianness
94      * of this platform is big.
95      *
96      * @implNote
97      * The actual value for this field is injected by the JVM.
98      */
99 
100     static final boolean BIG_ENDIAN;
101 
102     /**
103      * Flag whose value is true if and only if the platform can
104      * perform unaligned accesses
105      *
106      * @implNote
107      * The actual value for this field is injected by the JVM.
108      */
109 
110     static final boolean UNALIGNED_ACCESS;
111 
112     // BEGIN Android-removed: Not used in Android.
113     /*
114     /**
115      * The size of an L1 data cache line which will be either a power
116      * of two or zero.
117      *
118      * <p>A non-zero value indicates that writeback to memory is
119      * enabled for the current processor. The value defines the
120      * natural alignment and size of any data cache line committed to
121      * memory by a single writeback operation. If data cache line
122      * writeback is not enabled for the current hardware the field
123      * will have value 0.
124      *
125      * @implNote
126      * The actual value for this field is injected by the JVM.
127      * /
128 
129     static final int DATA_CACHE_LINE_FLUSH_SIZE;
130      */
131     // END Android-removed: Not used in Android.
132 
133     static {
134         // Android-removed: Retrieved through Unsafe.addressSize().
135         // ADDRESS_SIZE0 = 0;
136         // Android-removed: Retrieved through Unsafe.pageSize().
137         // PAGE_SIZE = 0;
138         BIG_ENDIAN = false;
139         UNALIGNED_ACCESS = false;
140         // Android-removed: Not used in Android.
141         // DATA_CACHE_LINE_FLUSH_SIZE = 0;
142     }
143 }
144