0
|
1 /*
|
|
2 * Copyright 2000-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.oops;
|
|
26
|
|
27 import java.io.*;
|
|
28 import java.util.*;
|
|
29 import sun.jvm.hotspot.debugger.*;
|
|
30 import sun.jvm.hotspot.runtime.*;
|
|
31 import sun.jvm.hotspot.types.*;
|
|
32
|
|
33 // A TypeArray is an array containing basic types (non oop elements).
|
|
34 // It is used for arrays of {characters, singles, doubles, bytes, shorts, integers, longs}
|
|
35
|
|
36 public class TypeArray extends Array {
|
|
37 static {
|
|
38 VM.registerVMInitializedObserver(new Observer() {
|
|
39 public void update(Observable o, Object data) {
|
|
40 initialize(VM.getVM().getTypeDataBase());
|
|
41 }
|
|
42 });
|
|
43 }
|
|
44
|
|
45 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
|
|
46 Type type = db.lookupType("typeArrayOopDesc");
|
|
47 }
|
|
48
|
|
49 TypeArray(OopHandle handle, ObjectHeap heap) {
|
|
50 super(handle, heap);
|
|
51 }
|
|
52
|
|
53 public boolean isTypeArray() { return true; }
|
|
54
|
|
55 public byte getByteAt(long index) {
|
|
56 long offset = baseOffsetInBytes(BasicType.T_BYTE) + index * getHeap().getByteSize();
|
|
57 return getHandle().getJByteAt(offset);
|
|
58 }
|
|
59
|
|
60 public boolean getBooleanAt(long index) {
|
|
61 long offset = baseOffsetInBytes(BasicType.T_BOOLEAN) + index * getHeap().getBooleanSize();
|
|
62 return getHandle().getJBooleanAt(offset);
|
|
63 }
|
|
64
|
|
65 public char getCharAt(long index) {
|
|
66 long offset = baseOffsetInBytes(BasicType.T_CHAR) + index * getHeap().getCharSize();
|
|
67 return getHandle().getJCharAt(offset);
|
|
68 }
|
|
69
|
|
70 public int getIntAt(long index) {
|
|
71 long offset = baseOffsetInBytes(BasicType.T_INT) + index * getHeap().getIntSize();
|
|
72 return getHandle().getJIntAt(offset);
|
|
73 }
|
|
74
|
|
75 public short getShortAt(long index) {
|
|
76 long offset = baseOffsetInBytes(BasicType.T_SHORT) + index * getHeap().getShortSize();
|
|
77 return getHandle().getJShortAt(offset);
|
|
78 }
|
|
79
|
|
80 public long getLongAt(long index) {
|
|
81 long offset = baseOffsetInBytes(BasicType.T_LONG) + index * getHeap().getLongSize();
|
|
82 return getHandle().getJLongAt(offset);
|
|
83 }
|
|
84
|
|
85 public float getFloatAt(long index) {
|
|
86 long offset = baseOffsetInBytes(BasicType.T_FLOAT) + index * getHeap().getFloatSize();
|
|
87 return getHandle().getJFloatAt(offset);
|
|
88 }
|
|
89
|
|
90 public double getDoubleAt(long index) {
|
|
91 long offset = baseOffsetInBytes(BasicType.T_DOUBLE) + index * getHeap().getDoubleSize();
|
|
92 return getHandle().getJDoubleAt(offset);
|
|
93 }
|
|
94
|
|
95 public void printValueOn(PrintStream tty) {
|
|
96 TypeArrayKlass klass = (TypeArrayKlass) getKlass();
|
|
97 tty.print(klass.getTypeName());
|
|
98 }
|
|
99
|
|
100 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
|
|
101 super.iterateFields(visitor, doVMFields);
|
|
102 TypeArrayKlass klass = (TypeArrayKlass) getKlass();
|
|
103 int length = (int) getLength();
|
|
104 int type = (int) klass.getElementType();
|
|
105 for (int index = 0; index < length; index++) {
|
|
106 FieldIdentifier id = new IndexableFieldIdentifier(index);
|
|
107 switch (type) {
|
|
108 case TypeArrayKlass.T_BOOLEAN: {
|
|
109 long offset = baseOffsetInBytes(BasicType.T_BOOLEAN) + index * getHeap().getBooleanSize();
|
|
110 visitor.doBoolean(new BooleanField(id, offset, false), false);
|
|
111 break;
|
|
112 }
|
|
113 case TypeArrayKlass.T_CHAR: {
|
|
114 long offset = baseOffsetInBytes(BasicType.T_CHAR) + index * getHeap().getCharSize();
|
|
115 visitor.doChar(new CharField(id, offset, false), false);
|
|
116 break;
|
|
117 }
|
|
118 case TypeArrayKlass.T_FLOAT: {
|
|
119 long offset = baseOffsetInBytes(BasicType.T_FLOAT) + index * getHeap().getFloatSize();
|
|
120 visitor.doFloat(new FloatField(id, offset, false), false);
|
|
121 break;
|
|
122 }
|
|
123 case TypeArrayKlass.T_DOUBLE: {
|
|
124 long offset = baseOffsetInBytes(BasicType.T_DOUBLE) + index * getHeap().getDoubleSize();
|
|
125 visitor.doDouble(new DoubleField(id, offset, false), false);
|
|
126 break;
|
|
127 }
|
|
128 case TypeArrayKlass.T_BYTE: {
|
|
129 long offset = baseOffsetInBytes(BasicType.T_BYTE) + index * getHeap().getByteSize();
|
|
130 visitor.doByte(new ByteField(id, offset, false), false);
|
|
131 break;
|
|
132 }
|
|
133 case TypeArrayKlass.T_SHORT: {
|
|
134 long offset = baseOffsetInBytes(BasicType.T_SHORT) + index * getHeap().getShortSize();
|
|
135 visitor.doShort(new ShortField(id, offset, false), false);
|
|
136 break;
|
|
137 }
|
|
138 case TypeArrayKlass.T_INT: {
|
|
139 long offset = baseOffsetInBytes(BasicType.T_INT) + index * getHeap().getIntSize();
|
|
140 visitor.doInt(new IntField(id, offset, false), false);
|
|
141 break;
|
|
142 }
|
|
143 case TypeArrayKlass.T_LONG: {
|
|
144 long offset = baseOffsetInBytes(BasicType.T_LONG) + index * getHeap().getLongSize();
|
|
145 visitor.doLong(new LongField(id, offset, false), false);
|
|
146 break;
|
|
147 }
|
|
148 }
|
|
149 }
|
|
150 }
|
|
151 }
|