< prev index next >

src/hotspot/share/code/debugInfo.cpp

Print this page




  39 : CompressedWriteStream(initial_size) {
  40   _recorder = recorder;
  41 }
  42 
  43 // Serializing oops
  44 
  45 void DebugInfoWriteStream::write_handle(jobject h) {
  46   write_int(recorder()->oop_recorder()->find_index(h));
  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   oop o = code()->oop_at(read_int());
  55   assert(oopDesc::is_oop_or_null(o), "oop only");
  56   return o;
  57 }
  58 
  59 ScopeValue* DebugInfoReadStream::read_object_value(bool is_auto_box) {
  60   int id = read_int();
  61 #ifdef ASSERT
  62   assert(_obj_pool != NULL, "object pool does not exist");
  63   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
  64     assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
  65   }
  66 #endif
  67   ObjectValue* result = is_auto_box ? new AutoBoxObjectValue(id) : new ObjectValue(id);
  68   // Cache the object since an object field could reference it.
  69   _obj_pool->push(result);
  70   result->read_object(this);
  71   return result;
  72 }
  73 
  74 ScopeValue* DebugInfoReadStream::get_cached_object() {
  75   int id = read_int();
  76   assert(_obj_pool != NULL, "object pool does not exist");
  77   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
  78     ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();
  79     if (ov->id() == id) {
  80       return ov;
  81     }
  82   }
  83   ShouldNotReachHere();
  84   return NULL;
  85 }
  86 
  87 // Serializing scope values
  88 
  89 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1,  CONSTANT_OOP_CODE = 2,
  90                           CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
  91                           OBJECT_CODE = 5,        OBJECT_ID_CODE = 6,
  92                           AUTO_BOX_OBJECT_CODE = 7 };
  93 
  94 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
  95   ScopeValue* result = NULL;
  96   switch(stream->read_int()) {
  97    case LOCATION_CODE:        result = new LocationValue(stream);                        break;
  98    case CONSTANT_INT_CODE:    result = new ConstantIntValue(stream);                     break;
  99    case CONSTANT_OOP_CODE:    result = new ConstantOopReadValue(stream);                 break;
 100    case CONSTANT_LONG_CODE:   result = new ConstantLongValue(stream);                    break;
 101    case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream);                  break;
 102    case OBJECT_CODE:          result = stream->read_object_value(false /*is_auto_box*/); break;
 103    case AUTO_BOX_OBJECT_CODE: result = stream->read_object_value(true /*is_auto_box*/);  break;
 104    case OBJECT_ID_CODE:       result = stream->get_cached_object();                      break;
 105    default: ShouldNotReachHere();
 106   }
 107   return result;
 108 }
 109 
 110 // LocationValue
 111 
 112 LocationValue::LocationValue(DebugInfoReadStream* stream) {
 113   _location = Location(stream);
 114 }
 115 
 116 void LocationValue::write_on(DebugInfoWriteStream* stream) {
 117   stream->write_int(LOCATION_CODE);
 118   location().write_on(stream);
 119 }
 120 
 121 void LocationValue::print_on(outputStream* st) const {
 122   location().print_on(st);
 123 }
 124 


 127 void ObjectValue::set_value(oop value) {
 128   _value = Handle(Thread::current(), value);
 129 }
 130 
 131 void ObjectValue::read_object(DebugInfoReadStream* stream) {
 132   _klass = read_from(stream);
 133   assert(_klass->is_constant_oop(), "should be constant java mirror oop");
 134   int length = stream->read_int();
 135   for (int i = 0; i < length; i++) {
 136     ScopeValue* val = read_from(stream);
 137     _field_values.append(val);
 138   }
 139 }
 140 
 141 void ObjectValue::write_on(DebugInfoWriteStream* stream) {
 142   if (_visited) {
 143     stream->write_int(OBJECT_ID_CODE);
 144     stream->write_int(_id);
 145   } else {
 146     _visited = true;
 147     stream->write_int(is_auto_box() ? AUTO_BOX_OBJECT_CODE : OBJECT_CODE);
 148     stream->write_int(_id);
 149     _klass->write_on(stream);
 150     int length = _field_values.length();
 151     stream->write_int(length);
 152     for (int i = 0; i < length; i++) {
 153       _field_values.at(i)->write_on(stream);
 154     }
 155   }
 156 }
 157 
 158 void ObjectValue::print_on(outputStream* st) const {
 159   st->print("%s[%d]", is_auto_box() ? "box_obj" : "obj", _id);
 160 }
 161 
 162 void ObjectValue::print_fields_on(outputStream* st) const {
 163 #ifndef PRODUCT
 164   if (_field_values.length() > 0) {
 165     _field_values.at(0)->print_on(st);
 166   }
 167   for (int i = 1; i < _field_values.length(); i++) {
 168     st->print(", ");
 169     _field_values.at(i)->print_on(st);
 170   }
 171 #endif
 172 }
 173 
 174 // ConstantIntValue
 175 
 176 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
 177   _value = stream->read_signed_int();
 178 }
 179 




  39 : CompressedWriteStream(initial_size) {
  40   _recorder = recorder;
  41 }
  42 
  43 // Serializing oops
  44 
  45 void DebugInfoWriteStream::write_handle(jobject h) {
  46   write_int(recorder()->oop_recorder()->find_index(h));
  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   oop o = code()->oop_at(read_int());
  55   assert(oopDesc::is_oop_or_null(o), "oop only");
  56   return o;
  57 }
  58 
  59 ScopeValue* DebugInfoReadStream::read_object_value() {
  60   int id = read_int();
  61 #ifdef ASSERT
  62   assert(_obj_pool != NULL, "object pool does not exist");
  63   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
  64     assert(_obj_pool->at(i)->as_ObjectValue()->id() != id, "should not be read twice");
  65   }
  66 #endif
  67   ObjectValue* result = new ObjectValue(id);
  68   // Cache the object since an object field could reference it.
  69   _obj_pool->push(result);
  70   result->read_object(this);
  71   return result;
  72 }
  73 
  74 ScopeValue* DebugInfoReadStream::get_cached_object() {
  75   int id = read_int();
  76   assert(_obj_pool != NULL, "object pool does not exist");
  77   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
  78     ObjectValue* ov = _obj_pool->at(i)->as_ObjectValue();
  79     if (ov->id() == id) {
  80       return ov;
  81     }
  82   }
  83   ShouldNotReachHere();
  84   return NULL;
  85 }
  86 
  87 // Serializing scope values
  88 
  89 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1,  CONSTANT_OOP_CODE = 2,
  90                           CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
  91                           OBJECT_CODE = 5,        OBJECT_ID_CODE = 6 };

  92 
  93 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
  94   ScopeValue* result = NULL;
  95   switch(stream->read_int()) {
  96    case LOCATION_CODE:        result = new LocationValue(stream);        break;
  97    case CONSTANT_INT_CODE:    result = new ConstantIntValue(stream);     break;
  98    case CONSTANT_OOP_CODE:    result = new ConstantOopReadValue(stream); break;
  99    case CONSTANT_LONG_CODE:   result = new ConstantLongValue(stream);    break;
 100    case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream);  break;
 101    case OBJECT_CODE:          result = stream->read_object_value();      break;
 102    case OBJECT_ID_CODE:       result = stream->get_cached_object();      break;

 103    default: ShouldNotReachHere();
 104   }
 105   return result;
 106 }
 107 
 108 // LocationValue
 109 
 110 LocationValue::LocationValue(DebugInfoReadStream* stream) {
 111   _location = Location(stream);
 112 }
 113 
 114 void LocationValue::write_on(DebugInfoWriteStream* stream) {
 115   stream->write_int(LOCATION_CODE);
 116   location().write_on(stream);
 117 }
 118 
 119 void LocationValue::print_on(outputStream* st) const {
 120   location().print_on(st);
 121 }
 122 


 125 void ObjectValue::set_value(oop value) {
 126   _value = Handle(Thread::current(), value);
 127 }
 128 
 129 void ObjectValue::read_object(DebugInfoReadStream* stream) {
 130   _klass = read_from(stream);
 131   assert(_klass->is_constant_oop(), "should be constant java mirror oop");
 132   int length = stream->read_int();
 133   for (int i = 0; i < length; i++) {
 134     ScopeValue* val = read_from(stream);
 135     _field_values.append(val);
 136   }
 137 }
 138 
 139 void ObjectValue::write_on(DebugInfoWriteStream* stream) {
 140   if (_visited) {
 141     stream->write_int(OBJECT_ID_CODE);
 142     stream->write_int(_id);
 143   } else {
 144     _visited = true;
 145     stream->write_int(OBJECT_CODE);
 146     stream->write_int(_id);
 147     _klass->write_on(stream);
 148     int length = _field_values.length();
 149     stream->write_int(length);
 150     for (int i = 0; i < length; i++) {
 151       _field_values.at(i)->write_on(stream);
 152     }
 153   }
 154 }
 155 
 156 void ObjectValue::print_on(outputStream* st) const {
 157   st->print("obj[%d]", _id);
 158 }
 159 
 160 void ObjectValue::print_fields_on(outputStream* st) const {
 161 #ifndef PRODUCT
 162   if (_field_values.length() > 0) {
 163     _field_values.at(0)->print_on(st);
 164   }
 165   for (int i = 1; i < _field_values.length(); i++) {
 166     st->print(", ");
 167     _field_values.at(i)->print_on(st);
 168   }
 169 #endif
 170 }
 171 
 172 // ConstantIntValue
 173 
 174 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
 175   _value = stream->read_signed_int();
 176 }
 177 


< prev index next >