/* * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ package sun.jvm.hotspot.runtime; import java.util.Observer; import sun.jvm.hotspot.types.TypeDataBase; /** Encapsulates the BasicType enum in globalDefinitions.hpp in the VM. */ public class BasicType { private static int tBoolean; private static int tChar; private static int tFloat; private static int tDouble; private static int tByte; private static int tShort; private static int tInt; private static int tLong; private static int tObject; private static int tArray; private static int tVoid; private static int tAddress; private static int tNarrowOop; private static int tMetadata; private static int tNarrowKlass; private static int tConflict; private static int tIllegal; public static BasicType T_BOOLEAN; public static BasicType T_CHAR; public static BasicType T_FLOAT; public static BasicType T_DOUBLE; public static BasicType T_BYTE; public static BasicType T_SHORT; public static BasicType T_INT; public static BasicType T_LONG; public static BasicType T_OBJECT; public static BasicType T_ARRAY; public static BasicType T_VOID; public static BasicType T_ADDRESS; public static BasicType T_NARROWOOP; public static BasicType T_METADATA; public static BasicType T_NARROWKLASS; public static BasicType T_CONFLICT; public static BasicType T_ILLEGAL; static { VM.registerVMInitializedObserver( (o, d) -> initialize(VM.getVM().getTypeDataBase())); } private static synchronized void initialize(TypeDataBase db) { tBoolean = db.lookupIntConstant("T_BOOLEAN").intValue(); tChar = db.lookupIntConstant("T_CHAR").intValue(); tFloat = db.lookupIntConstant("T_FLOAT").intValue(); tDouble = db.lookupIntConstant("T_DOUBLE").intValue(); tByte = db.lookupIntConstant("T_BYTE").intValue(); tShort = db.lookupIntConstant("T_SHORT").intValue(); tInt = db.lookupIntConstant("T_INT").intValue(); tLong = db.lookupIntConstant("T_LONG").intValue(); tObject = db.lookupIntConstant("T_OBJECT").intValue(); tArray = db.lookupIntConstant("T_ARRAY").intValue(); tVoid = db.lookupIntConstant("T_VOID").intValue(); tAddress = db.lookupIntConstant("T_ADDRESS").intValue(); tNarrowOop = db.lookupIntConstant("T_NARROWOOP").intValue(); tMetadata = db.lookupIntConstant("T_METADATA").intValue(); tNarrowKlass = db.lookupIntConstant("T_NARROWKLASS").intValue(); tConflict = db.lookupIntConstant("T_CONFLICT").intValue(); tIllegal = db.lookupIntConstant("T_ILLEGAL").intValue(); T_BOOLEAN = new BasicType(tBoolean); T_CHAR = new BasicType(tChar); T_FLOAT = new BasicType(tFloat); T_DOUBLE = new BasicType(tDouble); T_BYTE = new BasicType(tByte); T_SHORT = new BasicType(tShort); T_INT = new BasicType(tInt); T_LONG = new BasicType(tLong); T_OBJECT = new BasicType(tObject); T_ARRAY = new BasicType(tArray); T_VOID = new BasicType(tVoid); T_ADDRESS = new BasicType(tAddress); T_NARROWOOP = new BasicType(tNarrowOop); T_METADATA = new BasicType(tMetadata); T_NARROWKLASS = new BasicType(tNarrowKlass); T_CONFLICT = new BasicType(tConflict); T_ILLEGAL = new BasicType(tIllegal); } public static int getTBoolean() { return tBoolean; } public static int getTChar() { return tChar; } public static int getTFloat() { return tFloat; } public static int getTDouble() { return tDouble; } public static int getTByte() { return tByte; } public static int getTShort() { return tShort; } public static int getTInt() { return tInt; } public static int getTLong() { return tLong; } public static int getTObject() { return tObject; } public static int getTArray() { return tArray; } public static int getTVoid() { return tVoid; } public static int getTAddress() { return tAddress; } public static int getTNarrowOop() { return tNarrowOop; } public static int getTMetadata() { return tMetadata; } public static int getTNarrowKlass() { return tNarrowKlass; } /** For stack value type with conflicting contents */ public static int getTConflict() { return tConflict; } public static int getTIllegal() { return tIllegal; } public static BasicType intToBasicType(int i) { if (i == tBoolean) { return T_BOOLEAN; } else if (i == tChar) { return T_CHAR; } else if (i == tFloat) { return T_FLOAT; } else if (i == tDouble) { return T_DOUBLE; } else if (i == tByte) { return T_BYTE; } else if (i == tShort) { return T_SHORT; } else if (i == tInt) { return T_INT; } else if (i == tLong) { return T_LONG; } else if (i == tObject) { return T_OBJECT; } else if (i == tArray) { return T_ARRAY; } else if (i == tVoid) { return T_VOID; } else if (i == tAddress) { return T_ADDRESS; } else if (i == tNarrowOop) { return T_NARROWOOP; } else if (i == tMetadata) { return T_METADATA; } else if (i == tNarrowKlass) { return T_NARROWKLASS; } else { return T_ILLEGAL; } } public static BasicType charToBasicType(char c) { switch( c ) { case 'B': return T_BYTE; case 'C': return T_CHAR; case 'D': return T_DOUBLE; case 'F': return T_FLOAT; case 'I': return T_INT; case 'J': return T_LONG; case 'S': return T_SHORT; case 'Z': return T_BOOLEAN; case 'V': return T_VOID; case 'L': return T_OBJECT; case '[': return T_ARRAY; } return T_ILLEGAL; } public static int charToType(char c) { return charToBasicType(c).getType(); } public int getType() { return type; } public String getName() { if (type == tBoolean) { return "boolean"; } else if (type == tChar) { return "char"; } else if (type == tFloat) { return "float"; } else if (type == tDouble) { return "double"; } else if (type == tByte) { return "byte"; } else if (type == tShort) { return "short"; } else if (type == tInt) { return "int"; } else if (type == tLong) { return "long"; } else if (type == tObject) { return "object"; } else if (type == tArray) { return "array"; } else if (type == tVoid) { return "void"; } else if (type == tAddress) { return "address"; } else if (type == tNarrowOop) { return "narrow oop"; } else if (type == tMetadata) { return "metadata"; } else if (type == tNarrowKlass) { return "narrow klass"; } else if (type == tConflict) { return "conflict"; } else { return "ILLEGAL TYPE"; } } //-- Internals only below this point private BasicType(int type) { this.type = type; } private int type; }