src/share/vm/code/debugInfo.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 479
52fed2ec0afb
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 1997-2006 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  */
    25 # include "incls/_precompiled.incl"
    26 # include "incls/_debugInfo.cpp.incl"
    28 // Comstructors
    30 DebugInfoWriteStream::DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size)
    31 : CompressedWriteStream(initial_size) {
    32   _recorder = recorder;
    33 }
    35 // Serializing oops
    37 void DebugInfoWriteStream::write_handle(jobject h) {
    38   write_int(recorder()->oop_recorder()->find_index(h));
    39 }
    41 ScopeValue* DebugInfoReadStream::read_object_value() {
    42   int id = read_int();
    43 #ifdef ASSERT
    44   assert(_obj_pool != NULL, "object pool does not exist");
    45   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
    46     assert(((ObjectValue*) _obj_pool->at(i))->id() != id, "should not be read twice");
    47   }
    48 #endif
    49   ObjectValue* result = new ObjectValue(id);
    50   _obj_pool->append(result);
    51   result->read_object(this);
    52   return result;
    53 }
    55 ScopeValue* DebugInfoReadStream::get_cached_object() {
    56   int id = read_int();
    57   assert(_obj_pool != NULL, "object pool does not exist");
    58   for (int i = _obj_pool->length() - 1; i >= 0; i--) {
    59     ObjectValue* sv = (ObjectValue*) _obj_pool->at(i);
    60     if (sv->id() == id) {
    61       return sv;
    62     }
    63   }
    64   ShouldNotReachHere();
    65   return NULL;
    66 }
    68 // Serializing scope values
    70 enum { LOCATION_CODE = 0, CONSTANT_INT_CODE = 1,  CONSTANT_OOP_CODE = 2,
    71                           CONSTANT_LONG_CODE = 3, CONSTANT_DOUBLE_CODE = 4,
    72                           OBJECT_CODE = 5,        OBJECT_ID_CODE = 6 };
    74 ScopeValue* ScopeValue::read_from(DebugInfoReadStream* stream) {
    75   ScopeValue* result = NULL;
    76   switch(stream->read_int()) {
    77    case LOCATION_CODE:        result = new LocationValue(stream);        break;
    78    case CONSTANT_INT_CODE:    result = new ConstantIntValue(stream);     break;
    79    case CONSTANT_OOP_CODE:    result = new ConstantOopReadValue(stream); break;
    80    case CONSTANT_LONG_CODE:   result = new ConstantLongValue(stream);    break;
    81    case CONSTANT_DOUBLE_CODE: result = new ConstantDoubleValue(stream);  break;
    82    case OBJECT_CODE:          result = stream->read_object_value();      break;
    83    case OBJECT_ID_CODE:       result = stream->get_cached_object();      break;
    84    default: ShouldNotReachHere();
    85   }
    86   return result;
    87 }
    89 // LocationValue
    91 LocationValue::LocationValue(DebugInfoReadStream* stream) {
    92   _location = Location(stream);
    93 }
    95 void LocationValue::write_on(DebugInfoWriteStream* stream) {
    96   stream->write_int(LOCATION_CODE);
    97   location().write_on(stream);
    98 }
   100 void LocationValue::print_on(outputStream* st) const {
   101   location().print_on(st);
   102 }
   104 // ObjectValue
   106 void ObjectValue::read_object(DebugInfoReadStream* stream) {
   107   _klass = read_from(stream);
   108   assert(_klass->is_constant_oop(), "should be constant klass oop");
   109   int length = stream->read_int();
   110   for (int i = 0; i < length; i++) {
   111     ScopeValue* val = read_from(stream);
   112     _field_values.append(val);
   113   }
   114 }
   116 void ObjectValue::write_on(DebugInfoWriteStream* stream) {
   117   if (_visited) {
   118     stream->write_int(OBJECT_ID_CODE);
   119     stream->write_int(_id);
   120   } else {
   121     _visited = true;
   122     stream->write_int(OBJECT_CODE);
   123     stream->write_int(_id);
   124     _klass->write_on(stream);
   125     int length = _field_values.length();
   126     stream->write_int(length);
   127     for (int i = 0; i < length; i++) {
   128       _field_values.at(i)->write_on(stream);
   129     }
   130   }
   131 }
   133 void ObjectValue::print_on(outputStream* st) const {
   134   st->print("obj[%d]", _id);
   135 }
   137 void ObjectValue::print_fields_on(outputStream* st) const {
   138 #ifndef PRODUCT
   139   if (_field_values.length() > 0) {
   140     _field_values.at(0)->print_on(st);
   141   }
   142   for (int i = 1; i < _field_values.length(); i++) {
   143     st->print(", ");
   144     _field_values.at(i)->print_on(st);
   145   }
   146 #endif
   147 }
   149 // ConstantIntValue
   151 ConstantIntValue::ConstantIntValue(DebugInfoReadStream* stream) {
   152   _value = stream->read_signed_int();
   153 }
   155 void ConstantIntValue::write_on(DebugInfoWriteStream* stream) {
   156   stream->write_int(CONSTANT_INT_CODE);
   157   stream->write_signed_int(value());
   158 }
   160 void ConstantIntValue::print_on(outputStream* st) const {
   161   st->print("%d", value());
   162 }
   164 // ConstantLongValue
   166 ConstantLongValue::ConstantLongValue(DebugInfoReadStream* stream) {
   167   _value = stream->read_long();
   168 }
   170 void ConstantLongValue::write_on(DebugInfoWriteStream* stream) {
   171   stream->write_int(CONSTANT_LONG_CODE);
   172   stream->write_long(value());
   173 }
   175 void ConstantLongValue::print_on(outputStream* st) const {
   176   st->print(INT64_FORMAT, value());
   177 }
   179 // ConstantDoubleValue
   181 ConstantDoubleValue::ConstantDoubleValue(DebugInfoReadStream* stream) {
   182   _value = stream->read_double();
   183 }
   185 void ConstantDoubleValue::write_on(DebugInfoWriteStream* stream) {
   186   stream->write_int(CONSTANT_DOUBLE_CODE);
   187   stream->write_double(value());
   188 }
   190 void ConstantDoubleValue::print_on(outputStream* st) const {
   191   st->print("%f", value());
   192 }
   194 // ConstantOopWriteValue
   196 void ConstantOopWriteValue::write_on(DebugInfoWriteStream* stream) {
   197   stream->write_int(CONSTANT_OOP_CODE);
   198   stream->write_handle(value());
   199 }
   201 void ConstantOopWriteValue::print_on(outputStream* st) const {
   202   JNIHandles::resolve(value())->print_value_on(st);
   203 }
   206 // ConstantOopReadValue
   208 ConstantOopReadValue::ConstantOopReadValue(DebugInfoReadStream* stream) {
   209   _value = Handle(stream->read_oop());
   210 }
   212 void ConstantOopReadValue::write_on(DebugInfoWriteStream* stream) {
   213   ShouldNotReachHere();
   214 }
   216 void ConstantOopReadValue::print_on(outputStream* st) const {
   217   value()()->print_value_on(st);
   218 }
   221 // MonitorValue
   223 MonitorValue::MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated) {
   224   _owner       = owner;
   225   _basic_lock  = basic_lock;
   226   _eliminated  = eliminated;
   227 }
   229 MonitorValue::MonitorValue(DebugInfoReadStream* stream) {
   230   _basic_lock  = Location(stream);
   231   _owner       = ScopeValue::read_from(stream);
   232   _eliminated  = (stream->read_bool() != 0);
   233 }
   235 void MonitorValue::write_on(DebugInfoWriteStream* stream) {
   236   _basic_lock.write_on(stream);
   237   _owner->write_on(stream);
   238   stream->write_bool(_eliminated);
   239 }
   241 #ifndef PRODUCT
   242 void MonitorValue::print_on(outputStream* st) const {
   243   st->print("monitor{");
   244   owner()->print_on(st);
   245   st->print(",");
   246   basic_lock().print_on(st);
   247   st->print("}");
   248   if (_eliminated) {
   249     st->print(" (eliminated)");
   250   }
   251 }
   252 #endif

mercurial