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