View Javadoc
1   /*
2    * Copyright (c) 2000, 2013, 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      vtableLen          = new CIntField(type.getCIntegerField("_vtable_len"), 0);
52      componentMirror    = new OopField(type.getOopField("_component_mirror"), 0);
53      javaLangCloneableName = null;
54      javaLangObjectName = null;
55      javaIoSerializableName = null;
56    }
57  
58    public ArrayKlass(Address addr) {
59      super(addr);
60    }
61  
62    private static CIntField dimension;
63    private static MetadataField  higherDimension;
64    private static MetadataField  lowerDimension;
65    private static CIntField vtableLen;
66    private static OopField  componentMirror;
67  
68    public Klass getJavaSuper() {
69      SystemDictionary sysDict = VM.getVM().getSystemDictionary();
70      return sysDict.getObjectKlass();
71    }
72  
73    public long  getDimension()       { return         dimension.getValue(this); }
74    public Klass getHigherDimension() { return (Klass) higherDimension.getValue(this); }
75    public Klass getLowerDimension()  { return (Klass) lowerDimension.getValue(this); }
76    public long  getVtableLen()       { return         vtableLen.getValue(this); }
77    public Oop   getComponentMirror() { return         componentMirror.getValue(this); }
78  
79    // constant class names - javaLangCloneable, javaIoSerializable, javaLangObject
80    // Initialized lazily to avoid initialization ordering dependencies between ArrayKlass and SymbolTable
81    private static Symbol javaLangCloneableName;
82    private static Symbol javaLangObjectName;
83    private static Symbol javaIoSerializableName;
84    private static Symbol javaLangCloneableName() {
85      if (javaLangCloneableName == null) {
86        javaLangCloneableName = VM.getVM().getSymbolTable().probe("java/lang/Cloneable");
87      }
88      return javaLangCloneableName;
89    }
90  
91    private static Symbol javaLangObjectName() {
92      if (javaLangObjectName == null) {
93        javaLangObjectName = VM.getVM().getSymbolTable().probe("java/lang/Object");
94      }
95      return javaLangObjectName;
96    }
97  
98    private static Symbol javaIoSerializableName() {
99      if (javaIoSerializableName == null) {
100       javaIoSerializableName = VM.getVM().getSymbolTable().probe("java/io/Serializable");
101     }
102     return javaIoSerializableName;
103   }
104 
105   public int getClassStatus() {
106      return JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED | JVMDIClassStatus.INITIALIZED;
107   }
108 
109   public long computeModifierFlags() {
110      return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
111   }
112 
113   public long getArrayHeaderInBytes() {
114     return Bits.maskBits(getLayoutHelper() >> LH_HEADER_SIZE_SHIFT, 0xFF);
115   }
116 
117   public int getLog2ElementSize() {
118     return Bits.maskBits(getLayoutHelper() >> LH_LOG2_ELEMENT_SIZE_SHIFT, 0xFF);
119   }
120 
121   public int getElementType() {
122     return Bits.maskBits(getLayoutHelper() >> LH_ELEMENT_TYPE_SHIFT, 0xFF);
123   }
124 
125   boolean computeSubtypeOf(Klass k) {
126     // An array is a subtype of Serializable, Clonable, and Object
127     Symbol name = k.getName();
128     if (name != null && (name.equals(javaIoSerializableName()) ||
129                          name.equals(javaLangCloneableName()) ||
130                          name.equals(javaLangObjectName()))) {
131       return true;
132     } else {
133       return false;
134     }
135   }
136 
137   public void printValueOn(PrintStream tty) {
138     tty.print("ArrayKlass");
139   }
140 
141   public void iterateFields(MetadataVisitor visitor) {
142     super.iterateFields(visitor);
143       visitor.doCInt(dimension, true);
144     visitor.doMetadata(higherDimension, true);
145     visitor.doMetadata(lowerDimension, true);
146       visitor.doCInt(vtableLen, true);
147       visitor.doOop(componentMirror, true);
148     }
149   }