annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayReferenceImpl.java @ 2426:1d1603768966

7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
author trims
date Tue, 05 Apr 2011 14:12:31 -0700
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.Iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.oops.Array;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.runtime.BasicType;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public class ArrayReferenceImpl extends ObjectReferenceImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
39 implements ArrayReference
a61af66fc99e Initial load
duke
parents:
diff changeset
40 {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private int length;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 ArrayReferenceImpl(VirtualMachine aVm, sun.jvm.hotspot.oops.Array aRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 super(aVm, aRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 length = (int) aRef.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ArrayTypeImpl arrayType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return (ArrayTypeImpl)type();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * Return array length.
a61af66fc99e Initial load
duke
parents:
diff changeset
53 */
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public int length() {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return length;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public Value getValue(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 List list = getValues(index, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return (Value)list.get(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public List getValues() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return getValues(0, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
68 * Validate that the range to set/get is valid.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 * length of -1 (meaning rest of array) has been converted
a61af66fc99e Initial load
duke
parents:
diff changeset
70 * before entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 */
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private void validateArrayAccess(int index, int len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // because length can be computed from index,
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // index must be tested first for correct error message
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if ((index < 0) || (index > length())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 throw new IndexOutOfBoundsException(
a61af66fc99e Initial load
duke
parents:
diff changeset
77 "Invalid array index: " + index);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (len < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 throw new IndexOutOfBoundsException(
a61af66fc99e Initial load
duke
parents:
diff changeset
81 "Invalid array range length: " + len);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (index + len > length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 throw new IndexOutOfBoundsException(
a61af66fc99e Initial load
duke
parents:
diff changeset
85 "Invalid array range: " +
a61af66fc99e Initial load
duke
parents:
diff changeset
86 index + " to " + (index + len - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public List getValues(int index, int len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (len == -1) { // -1 means the rest of the array
a61af66fc99e Initial load
duke
parents:
diff changeset
92 len = length() - index;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 validateArrayAccess(index, len);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 List vals = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (len == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return vals;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 sun.jvm.hotspot.oops.TypeArray typeArray = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 sun.jvm.hotspot.oops.ObjArray objArray = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (ref() instanceof sun.jvm.hotspot.oops.TypeArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 typeArray = (sun.jvm.hotspot.oops.TypeArray)ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } else if (ref() instanceof sun.jvm.hotspot.oops.ObjArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 objArray = (sun.jvm.hotspot.oops.ObjArray)ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 char c = arrayType().componentSignature().charAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 BasicType variableType = BasicType.charToBasicType(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 final int limit = index + len;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 for (int ii = index; ii < limit; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ValueImpl valueImpl;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (variableType == BasicType.T_BOOLEAN) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 valueImpl = (BooleanValueImpl) vm.mirrorOf(typeArray.getBooleanAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
118 } else if (variableType == BasicType.T_CHAR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 valueImpl = (CharValueImpl) vm.mirrorOf(typeArray.getCharAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
120 } else if (variableType == BasicType.T_FLOAT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 valueImpl = (FloatValueImpl) vm.mirrorOf(typeArray.getFloatAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
122 } else if (variableType == BasicType.T_DOUBLE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 valueImpl = (DoubleValueImpl) vm.mirrorOf(typeArray.getDoubleAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
124 } else if (variableType == BasicType.T_BYTE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 valueImpl = (ByteValueImpl) vm.mirrorOf(typeArray.getByteAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
126 } else if (variableType == BasicType.T_SHORT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 valueImpl = (ShortValueImpl) vm.mirrorOf(typeArray.getShortAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
128 } else if (variableType == BasicType.T_INT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 valueImpl = (IntegerValueImpl) vm.mirrorOf(typeArray.getIntAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
130 } else if (variableType == BasicType.T_LONG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 valueImpl = (LongValueImpl) vm.mirrorOf(typeArray.getLongAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
132 } else if (variableType == BasicType.T_OBJECT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // we may have an [Ljava/lang/Object; - i.e., Object[] with the
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // elements themselves may be arrays because every array is an Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
135 valueImpl = (ObjectReferenceImpl) vm.objectMirror(objArray.getObjAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } else if (variableType == BasicType.T_ARRAY) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 valueImpl = (ArrayReferenceImpl) vm.arrayMirror((Array) objArray.getObjAt(ii));
a61af66fc99e Initial load
duke
parents:
diff changeset
138 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 vals.add (valueImpl);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return vals;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public void setValue(int index, Value value)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
148 ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 vm.throwNotReadOnlyException("ArrayReference.setValue(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 public void setValues(List values)
a61af66fc99e Initial load
duke
parents:
diff changeset
153 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
154 ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 setValues(0, values, 0, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public void setValues(int index, List values,
a61af66fc99e Initial load
duke
parents:
diff changeset
159 int srcIndex, int length)
a61af66fc99e Initial load
duke
parents:
diff changeset
160 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
161 ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 vm.throwNotReadOnlyException("ArrayReference.setValue(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return "instance of " + arrayType().componentTypeName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
169 "[" + length() + "] (id=" + uniqueID() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }