Tue, 24 Dec 2013 11:48:39 -0800
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
Summary: Copyright year updated for files modified during 2013
Reviewed-by: twisti, iveresov
1 /*
2 * Copyright (c) 1997, 2012, 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 */
25 #include "precompiled.hpp"
26 #include "code/debugInfo.hpp"
27 #include "code/debugInfoRec.hpp"
28 #include "code/nmethod.hpp"
29 #include "runtime/handles.inline.hpp"
31 // Comstructors
33 DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
34 : CompressedWriteStream(initial_size) {
35 _recorder = recorder;
36 }
38 // Serializing oops
40 void DebugInfoWriteStream::write_handle(jobject h) {
41 write_int(recorder()->oop_recorder()->find_index(h));
42 }
44 void DebugInfoWriteStream::write_metadata(Metadata* h) {
45 write_int(recorder()->oop_recorder()->find_index(h));
46 }
48 ScopeValue* DebugInfoReadStream::read_object_value() {
49 int id = read_int();
50 #ifdef ASSERT
51 assert(_obj_pool != NULL, "object pool does not exist");
52 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
53 assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");
54 }
55 #endif
56 ObjectValue* result = new ObjectValue(id);
57 // Cache the object since an object field could reference it.
58 _obj_pool->push(result);
59 result->read_object(this);
60 return result;
61 }
63 ScopeValue* DebugInfoReadStream::get_cached_object() {
64 int id = read_int();
65 assert(_obj_pool != NULL, "object pool does not exist");
66 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
67 ObjectValue* ov = (ObjectValue*) _obj_pool->at(i);
68 if (ov->id() == id) {
69 return ov;
70 }
71 }
72 ShouldNotReachHere();
73 return NULL;
74 }
76 // Serializing scope values
78 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
79 CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
80 OBJECT_CODE = 5, OBJECT_ID_CODE = 6 };
82 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
83 ScopeValue* result = NULL;
84 switch(stream->read_int()) {
85 case LOCATION_CODE: result = new LocationValue(stream); break;
86 case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
87 case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
88 case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
89 case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
90 case OBJECT_CODE: result = stream->read_object_value(); break;
91 case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
92 default: ShouldNotReachHere();
93 }
94 return result;
95 }
97 // LocationValue
99 LocationValue::LocationValue(DebugInfoReadStream* stream) {
100 _location = Location(stream);
101 }
103 void LocationValue::write_on(DebugInfoWriteStream* stream) {
104 stream->write_int(LOCATION_CODE);
105 location().write_on(stream);
106 }
108 void LocationValue::print_on(outputStream* st) const {
109 location().print_on(st);
110 }
112 // ObjectValue
114 void ObjectValue::read_object(DebugInfoReadStream* stream) {
115 _klass = read_from(stream);
116 assert(_klass->is_constant_oop(), "should be constant java mirror oop");
117 int length = stream->read_int();
118 for (int i = 0; i < length; i++) {
119 ScopeValue* val = read_from(stream);
120 _field_values.append(val);
121 }
122 }
124 void ObjectValue::write_on(DebugInfoWriteStream* stream) {
125 if (_visited) {
126 stream->write_int(OBJECT_ID_CODE);
127 stream->write_int(_id);
128 } else {
129 _visited = true;
130 stream->write_int(OBJECT_CODE);
131 stream->write_int(_id);
132 _klass->write_on(stream);
133 int length = _field_values.length();
134 stream->write_int(length);
135 for (int i = 0; i < length; i++) {
136 _field_values.at(i)->write_on(stream);
137 }
138 }
139 }
141 void ObjectValue::print_on(outputStream* st) const {
142 st->print("obj[%d]", _id);
143 }
145 void ObjectValue::print_fields_on(outputStream* st) const {
146 #ifndef PRODUCT
147 if (_field_values.length() > 0) {
148 _field_values.at(0)->print_on(st);
149 }
150 for (int i = 1; i < _field_values.length(); i++) {
151 st->print(", ");
152 _field_values.at(i)->print_on(st);
153 }
154 #endif
155 }
157 // ConstantIntValue
159 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
160 _value = stream->read_signed_int();
161 }
163 void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
164 stream->write_int(CONSTANT_INT_CODE);
165 stream->write_signed_int(value());
166 }
168 void ConstantIntValue::print_on(outputStream* st) const {
169 st->print("%d", value());
170 }
172 // ConstantLongValue
174 ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
175 _value = stream->read_long();
176 }
178 void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {
179 stream->write_int(CONSTANT_LONG_CODE);
180 stream->write_long(value());
181 }
183 void ConstantLongValue::print_on(outputStream* st) const {
184 st->print(INT64_FORMAT, value());
185 }
187 // ConstantDoubleValue
189 ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
190 _value = stream->read_double();
191 }
193 void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
194 stream->write_int(CONSTANT_DOUBLE_CODE);
195 stream->write_double(value());
196 }
198 void ConstantDoubleValue::print_on(outputStream* st) const {
199 st->print("%f", value());
200 }
202 // ConstantOopWriteValue
204 void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
205 assert(JNIHandles::resolve(value()) == NULL ||
206 Universe::heap()->is_in_reserved(JNIHandles::resolve(value())),
207 "Should be in heap");
208 stream->write_int(CONSTANT_OOP_CODE);
209 stream->write_handle(value());
210 }
212 void ConstantOopWriteValue::print_on(outputStream* st) const {
213 JNIHandles::resolve(value())->print_value_on(st);
214 }
217 // ConstantOopReadValue
219 ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
220 _value = Handle(stream->read_oop());
221 assert(_value() == NULL ||
222 Universe::heap()->is_in_reserved(_value()), "Should be in heap");
223 }
225 void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
226 ShouldNotReachHere();
227 }
229 void ConstantOopReadValue::print_on(outputStream* st) const {
230 value()()->print_value_on(st);
231 }
234 // MonitorValue
236 MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
237 _owner = owner;
238 _basic_lock = basic_lock;
239 _eliminated = eliminated;
240 }
242 MonitorValue::MonitorValue(DebugInfoReadStream* stream) {
243 _basic_lock = Location(stream);
244 _owner = ScopeValue::read_from(stream);
245 _eliminated = (stream->read_bool() != 0);
246 }
248 void MonitorValue::write_on(DebugInfoWriteStream* stream) {
249 _basic_lock.write_on(stream);
250 _owner->write_on(stream);
251 stream->write_bool(_eliminated);
252 }
254 #ifndef PRODUCT
255 void MonitorValue::print_on(outputStream* st) const {
256 st->print("monitor{");
257 owner()->print_on(st);
258 st->print(",");
259 basic_lock().print_on(st);
260 st->print("}");
261 if (_eliminated) {
262 st->print(" (eliminated)");
263 }
264 }
265 #endif