1 /* 2 * Copyright (c) 2000, 2016, 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 package sun.jvm.hotspot.oops; 26 27 import java.io.*; 28 import java.util.*; 29 import sun.jvm.hotspot.utilities.*; 30 import sun.jvm.hotspot.debugger.*; 31 import sun.jvm.hotspot.memory.*; 32 import sun.jvm.hotspot.runtime.*; 33 import sun.jvm.hotspot.types.*; 34 35 // ArrayKlass is the abstract class for all array classes 36 37 public class ArrayKlass extends Klass { 38 static { 39 VM.registerVMInitializedObserver(new Observer() { 40 public void update(Observable o, Object data) { 41 initialize(VM.getVM().getTypeDataBase()); 42 } 43 }); 44 } 45 46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 47 Type type = db.lookupType("ArrayKlass"); 48 dimension = new CIntField(type.getCIntegerField("_dimension"), 0); 49 higherDimension = new MetadataField(type.getAddressField("_higher_dimension"), 0); 50 lowerDimension = new MetadataField(type.getAddressField("_lower_dimension"), 0); 51 javaLangCloneableName = null; 52 javaLangObjectName = null; 53 javaIoSerializableName = null; 54 } 55 56 public ArrayKlass(Address addr) { 57 super(addr); 58 } 59 60 private static CIntField dimension; 61 private static MetadataField higherDimension; 62 private static MetadataField lowerDimension; 63 64 public Klass getJavaSuper() { 65 SystemDictionary sysDict = VM.getVM().getSystemDictionary(); 66 return sysDict.getObjectKlass(); 67 } 68 69 public long getDimension() { return dimension.getValue(this); } 70 public Klass getHigherDimension() { return (Klass) higherDimension.getValue(this); } 71 public Klass getLowerDimension() { return (Klass) lowerDimension.getValue(this); } 72 73 // constant class names - javaLangCloneable, javaIoSerializable, javaLangObject 74 // Initialized lazily to avoid initialization ordering dependencies between ArrayKlass and SymbolTable 75 private static Symbol javaLangCloneableName; 76 private static Symbol javaLangObjectName; 77 private static Symbol javaIoSerializableName; 78 private static Symbol javaLangCloneableName() { 79 if (javaLangCloneableName == null) { 80 javaLangCloneableName = VM.getVM().getSymbolTable().probe("java/lang/Cloneable"); 81 } 82 return javaLangCloneableName; 83 } 84 85 private static Symbol javaLangObjectName() { 86 if (javaLangObjectName == null) { 87 javaLangObjectName = VM.getVM().getSymbolTable().probe("java/lang/Object"); 88 } 89 return javaLangObjectName; 90 } 91 92 private static Symbol javaIoSerializableName() { 93 if (javaIoSerializableName == null) { 94 javaIoSerializableName = VM.getVM().getSymbolTable().probe("java/io/Serializable"); 95 } 96 return javaIoSerializableName; 97 } 98 99 public int getClassStatus() { 100 return JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED | JVMDIClassStatus.INITIALIZED; 101 } 102 103 public long computeModifierFlags() { 104 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 105 } 106 107 public long getArrayHeaderInBytes() { 108 return Bits.maskBits(getLayoutHelper() >> LH_HEADER_SIZE_SHIFT, 0xFF); 109 } 110 111 public int getLog2ElementSize() { 112 return Bits.maskBits(getLayoutHelper() >> LH_LOG2_ELEMENT_SIZE_SHIFT, 0xFF); 113 } 114 115 public int getElementType() { 116 return Bits.maskBits(getLayoutHelper() >> LH_ELEMENT_TYPE_SHIFT, 0xFF); 117 } 118 119 boolean computeSubtypeOf(Klass k) { 120 // An array is a subtype of Serializable, Clonable, and Object 121 Symbol name = k.getName(); 122 if (name != null && (name.equals(javaIoSerializableName()) || 123 name.equals(javaLangCloneableName()) || 124 name.equals(javaLangObjectName()))) { 125 return true; 126 } else { 127 return false; 128 } 129 } 130 131 public void printValueOn(PrintStream tty) { 132 tty.print("ArrayKlass"); 133 } 134 135 public void iterateFields(MetadataVisitor visitor) { 136 super.iterateFields(visitor); 137 visitor.doCInt(dimension, true); 138 visitor.doMetadata(higherDimension, true); 139 visitor.doMetadata(lowerDimension, true); 140 } 141 }