47 }
48
49 void DebugInfoWriteStream::write_metadata(Metadata* h) {
50 write_int(recorder()->oop_recorder()->find_index(h));
51 }
52
53 oop DebugInfoReadStream::read_oop() {
54 nmethod* nm = const_cast<CompiledMethod*>(code())->as_nmethod_or_null();
55 oop o;
56 if (nm != NULL) {
57 // Despite these oops being found inside nmethods that are on-stack,
58 // they are not kept alive by all GCs (e.g. G1 and Shenandoah).
59 o = nm->oop_at_phantom(read_int());
60 } else {
61 o = code()->oop_at(read_int());
62 }
63 assert(oopDesc::is_oop_or_null(o), "oop only");
64 return o;
65 }
66
67 ScopeValue* DebugInfoReadStream::read_object_value(bool is_auto_box) {
68 int id = read_int();
69 #ifdef ASSERT
70 assert(_obj_pool != NULL, "object pool does not exist");
71 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
72 assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
73 }
74 #endif
75 ObjectValue* result = is_auto_box ? new AutoBoxObjectValue(id) : new ObjectValue(id);
76 // Cache the object since an object field could reference it.
77 _obj_pool->push(result);
78 result->read_object(this);
79 return result;
80 }
81
82 ScopeValue* DebugInfoReadStream::get_cached_object() {
83 int id = read_int();
84 assert(_obj_pool != NULL, "object pool does not exist");
85 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
86 ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();
87 if (ov->id() == id) {
88 return ov;
89 }
90 }
91 ShouldNotReachHere();
92 return NULL;
93 }
94
95 // Serializing scope values
96
97 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
98 CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
99 OBJECT_CODE = 5, OBJECT_ID_CODE = 6,
100 AUTO_BOX_OBJECT_CODE = 7, MARKER_CODE = 8 };
101
102 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
103 ScopeValue* result = NULL;
104 switch(stream->read_int()) {
105 case LOCATION_CODE: result = new LocationValue(stream); break;
106 case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
107 case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
108 case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
109 case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
110 case OBJECT_CODE: result = stream->read_object_value(false /*is_auto_box*/); break;
111 case AUTO_BOX_OBJECT_CODE: result = stream->read_object_value(true /*is_auto_box*/); break;
112 case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
113 case MARKER_CODE: result = new MarkerValue(); break;
114 default: ShouldNotReachHere();
115 }
116 return result;
117 }
118
119 // LocationValue
120
121 LocationValue::LocationValue(DebugInfoReadStream* stream) {
122 _location = Location(stream);
123 }
124
125 void LocationValue::write_on(DebugInfoWriteStream* stream) {
126 stream->write_int(LOCATION_CODE);
127 location().write_on(stream);
128 }
129
130 void LocationValue::print_on(outputStream* st) const {
131 location().print_on(st);
173 }
174 }
175 }
176
177 void ObjectValue::print_on(outputStream* st) const {
178 st->print("%s[%d]", is_auto_box() ? "box_obj" : "obj", _id);
179 }
180
181 void ObjectValue::print_fields_on(outputStream* st) const {
182 #ifndef PRODUCT
183 if (_field_values.length() > 0) {
184 _field_values.at(0)->print_on(st);
185 }
186 for (int i = 1; i < _field_values.length(); i++) {
187 st->print(", ");
188 _field_values.at(i)->print_on(st);
189 }
190 #endif
191 }
192
193 // ConstantIntValue
194
195 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
196 _value = stream->read_signed_int();
197 }
198
199 void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
200 stream->write_int(CONSTANT_INT_CODE);
201 stream->write_signed_int(value());
202 }
203
204 void ConstantIntValue::print_on(outputStream* st) const {
205 st->print("%d", value());
206 }
207
208 // ConstantLongValue
209
210 ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
211 _value = stream->read_long();
212 }
|
47 }
48
49 void DebugInfoWriteStream::write_metadata(Metadata* h) {
50 write_int(recorder()->oop_recorder()->find_index(h));
51 }
52
53 oop DebugInfoReadStream::read_oop() {
54 nmethod* nm = const_cast<CompiledMethod*>(code())->as_nmethod_or_null();
55 oop o;
56 if (nm != NULL) {
57 // Despite these oops being found inside nmethods that are on-stack,
58 // they are not kept alive by all GCs (e.g. G1 and Shenandoah).
59 o = nm->oop_at_phantom(read_int());
60 } else {
61 o = code()->oop_at(read_int());
62 }
63 assert(oopDesc::is_oop_or_null(o), "oop only");
64 return o;
65 }
66
67 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1, CONSTANT_OOP_CODE = 2,
68 CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
69 OBJECT_CODE = 5, OBJECT_ID_CODE = 6,
70 AUTO_BOX_OBJECT_CODE = 7, MARKER_CODE = 8,
71 STACK_OBJECT_CODE = 9 };
72
73 ScopeValue* DebugInfoReadStream::read_object_value(int type) {
74 int id = read_int();
75 #ifdef ASSERT
76 assert(_obj_pool != NULL, "object pool does not exist");
77 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
78 assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
79 }
80 #endif
81 ObjectValue* result;
82 if (type == AUTO_BOX_OBJECT_CODE) {
83 result = new AutoBoxObjectValue(id);
84 } else if (type == STACK_OBJECT_CODE) {
85 result = new StackObjectValue(id);
86 } else {
87 assert(type == OBJECT_CODE, "has to be an object");
88 result = new ObjectValue(id);
89 }
90 // Cache the object since an object field could reference it.
91 _obj_pool->push(result);
92 result->read_object(this);
93 return result;
94 }
95
96 ScopeValue* DebugInfoReadStream::get_cached_object() {
97 int id = read_int();
98 assert(_obj_pool != NULL, "object pool does not exist");
99 for (int i = _obj_pool->length() - 1; i >= 0; i--) {
100 ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();
101 if (ov->id() == id) {
102 return ov;
103 }
104 }
105 ShouldNotReachHere();
106 return NULL;
107 }
108
109 // Serializing scope values
110
111 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
112 ScopeValue* result = NULL;
113 switch(stream->read_int()) {
114 case LOCATION_CODE: result = new LocationValue(stream); break;
115 case CONSTANT_INT_CODE: result = new ConstantIntValue(stream); break;
116 case CONSTANT_OOP_CODE: result = new ConstantOopReadValue(stream); break;
117 case CONSTANT_LONG_CODE: result = new ConstantLongValue(stream); break;
118 case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream); break;
119 case OBJECT_CODE: result = stream->read_object_value(OBJECT_CODE); break;
120 case AUTO_BOX_OBJECT_CODE: result = stream->read_object_value(AUTO_BOX_OBJECT_CODE); break;
121 case STACK_OBJECT_CODE: result = stream->read_object_value(STACK_OBJECT_CODE); break;
122 case OBJECT_ID_CODE: result = stream->get_cached_object(); break;
123 case MARKER_CODE: result = new MarkerValue(); break;
124 default: ShouldNotReachHere();
125 }
126 return result;
127 }
128
129 // LocationValue
130
131 LocationValue::LocationValue(DebugInfoReadStream* stream) {
132 _location = Location(stream);
133 }
134
135 void LocationValue::write_on(DebugInfoWriteStream* stream) {
136 stream->write_int(LOCATION_CODE);
137 location().write_on(stream);
138 }
139
140 void LocationValue::print_on(outputStream* st) const {
141 location().print_on(st);
183 }
184 }
185 }
186
187 void ObjectValue::print_on(outputStream* st) const {
188 st->print("%s[%d]", is_auto_box() ? "box_obj" : "obj", _id);
189 }
190
191 void ObjectValue::print_fields_on(outputStream* st) const {
192 #ifndef PRODUCT
193 if (_field_values.length() > 0) {
194 _field_values.at(0)->print_on(st);
195 }
196 for (int i = 1; i < _field_values.length(); i++) {
197 st->print(", ");
198 _field_values.at(i)->print_on(st);
199 }
200 #endif
201 }
202
203 // StackObjectValue
204
205 StackObjectValue::StackObjectValue(int id, ScopeValue* klass, Location location, ConstantIntValue *field_length)
206 : ObjectValue(id, klass)
207 , _location(location)
208 , _field_length(field_length)
209 {
210 }
211
212 void StackObjectValue::read_object(DebugInfoReadStream* stream) {
213 ObjectValue::read_object(stream);
214 _location = Location(stream);
215 _field_length = (ConstantIntValue *)read_from(stream);
216 }
217
218 void StackObjectValue::write_on(DebugInfoWriteStream* stream) {
219 if (_visited) {
220 stream->write_int(OBJECT_ID_CODE);
221 stream->write_int(_id);
222 } else {
223 _visited = true;
224 stream->write_int(STACK_OBJECT_CODE);
225 stream->write_int(_id);
226 _klass->write_on(stream);
227 int length = _field_values.length();
228 stream->write_int(length);
229 for (int i = 0; i < length; i++) {
230 _field_values.at(i)->write_on(stream);
231 }
232 _location.write_on(stream);
233 _field_length->write_on(stream);
234 }
235 }
236
237 // ConstantIntValue
238
239 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
240 _value = stream->read_signed_int();
241 }
242
243 void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
244 stream->write_int(CONSTANT_INT_CODE);
245 stream->write_signed_int(value());
246 }
247
248 void ConstantIntValue::print_on(outputStream* st) const {
249 st->print("%d", value());
250 }
251
252 // ConstantLongValue
253
254 ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
255 _value = stream->read_long();
256 }
|