src/hotspot/share/code/debugInfo.hpp
changeset 47216 71c04702a3d5
parent 46271 979ebd346ecf
child 49449 ef5d5d343e2a
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 1997, 2017, 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  */
       
    24 
       
    25 #ifndef SHARE_VM_CODE_DEBUGINFO_HPP
       
    26 #define SHARE_VM_CODE_DEBUGINFO_HPP
       
    27 
       
    28 #include "code/compressedStream.hpp"
       
    29 #include "code/location.hpp"
       
    30 #include "code/nmethod.hpp"
       
    31 #include "code/oopRecorder.hpp"
       
    32 #include "runtime/stackValue.hpp"
       
    33 #include "runtime/thread.hpp"
       
    34 #include "utilities/growableArray.hpp"
       
    35 
       
    36 // Classes used for serializing debugging information.
       
    37 // These abstractions are introducted to provide symmetric
       
    38 // read and write operations.
       
    39 
       
    40 // ScopeValue        describes the value of a variable/expression in a scope
       
    41 // - LocationValue   describes a value in a given location (in frame or register)
       
    42 // - ConstantValue   describes a constant
       
    43 
       
    44 class ConstantOopReadValue;
       
    45 class ObjectValue;
       
    46 
       
    47 class ScopeValue: public ResourceObj {
       
    48  public:
       
    49   // Testers
       
    50   virtual bool is_location() const { return false; }
       
    51   virtual bool is_object() const { return false; }
       
    52   virtual bool is_constant_int() const { return false; }
       
    53   virtual bool is_constant_double() const { return false; }
       
    54   virtual bool is_constant_long() const { return false; }
       
    55   virtual bool is_constant_oop() const { return false; }
       
    56   virtual bool equals(ScopeValue* other) const { return false; }
       
    57 
       
    58   ConstantOopReadValue* as_ConstantOopReadValue() {
       
    59     assert(is_constant_oop(), "must be");
       
    60     return (ConstantOopReadValue*) this;
       
    61   }
       
    62 
       
    63   ObjectValue* as_ObjectValue() {
       
    64     assert(is_object(), "must be");
       
    65     return (ObjectValue*)this;
       
    66   }
       
    67 
       
    68   // Serialization of debugging information
       
    69   virtual void write_on(DebugInfoWriteStream* stream) = 0;
       
    70   static ScopeValue* read_from(DebugInfoReadStream* stream);
       
    71 };
       
    72 
       
    73 
       
    74 // A Location value describes a value in a given location; i.e. the corresponding
       
    75 // logical entity (e.g., a method temporary) lives in this location.
       
    76 
       
    77 class LocationValue: public ScopeValue {
       
    78  private:
       
    79   Location  _location;
       
    80  public:
       
    81   LocationValue(Location location)           { _location = location; }
       
    82   bool      is_location() const              { return true; }
       
    83   Location  location() const                 { return _location; }
       
    84 
       
    85   // Serialization of debugging information
       
    86   LocationValue(DebugInfoReadStream* stream);
       
    87   void write_on(DebugInfoWriteStream* stream);
       
    88 
       
    89   // Printing
       
    90   void print_on(outputStream* st) const;
       
    91 };
       
    92 
       
    93 
       
    94 // An ObjectValue describes an object eliminated by escape analysis.
       
    95 
       
    96 class ObjectValue: public ScopeValue {
       
    97  private:
       
    98   int                        _id;
       
    99   ScopeValue*                _klass;
       
   100   GrowableArray<ScopeValue*> _field_values;
       
   101   Handle                     _value;
       
   102   bool                       _visited;
       
   103 
       
   104  public:
       
   105   ObjectValue(int id, ScopeValue* klass)
       
   106      : _id(id)
       
   107      , _klass(klass)
       
   108      , _field_values()
       
   109      , _value()
       
   110      , _visited(false) {
       
   111     assert(klass->is_constant_oop(), "should be constant java mirror oop");
       
   112   }
       
   113 
       
   114   ObjectValue(int id)
       
   115      : _id(id)
       
   116      , _klass(NULL)
       
   117      , _field_values()
       
   118      , _value()
       
   119      , _visited(false) {}
       
   120 
       
   121   // Accessors
       
   122   bool                        is_object() const         { return true; }
       
   123   int                         id() const                { return _id; }
       
   124   ScopeValue*                 klass() const             { return _klass; }
       
   125   GrowableArray<ScopeValue*>* field_values()            { return &_field_values; }
       
   126   ScopeValue*                 field_at(int i) const     { return _field_values.at(i); }
       
   127   int                         field_size()              { return _field_values.length(); }
       
   128   Handle                      value() const             { return _value; }
       
   129   bool                        is_visited() const        { return _visited; }
       
   130 
       
   131   void                        set_value(oop value)      { _value = Handle(Thread::current(), value); }
       
   132   void                        set_visited(bool visited) { _visited = false; }
       
   133 
       
   134   // Serialization of debugging information
       
   135   void read_object(DebugInfoReadStream* stream);
       
   136   void write_on(DebugInfoWriteStream* stream);
       
   137 
       
   138   // Printing
       
   139   void print_on(outputStream* st) const;
       
   140   void print_fields_on(outputStream* st) const;
       
   141 };
       
   142 
       
   143 
       
   144 // A ConstantIntValue describes a constant int; i.e., the corresponding logical entity
       
   145 // is either a source constant or its computation has been constant-folded.
       
   146 
       
   147 class ConstantIntValue: public ScopeValue {
       
   148  private:
       
   149   jint _value;
       
   150  public:
       
   151   ConstantIntValue(jint value)         { _value = value; }
       
   152   jint value() const                   { return _value;  }
       
   153   bool is_constant_int() const         { return true;    }
       
   154   bool equals(ScopeValue* other) const { return false;   }
       
   155 
       
   156   // Serialization of debugging information
       
   157   ConstantIntValue(DebugInfoReadStream* stream);
       
   158   void write_on(DebugInfoWriteStream* stream);
       
   159 
       
   160   // Printing
       
   161   void print_on(outputStream* st) const;
       
   162 };
       
   163 
       
   164 class ConstantLongValue: public ScopeValue {
       
   165  private:
       
   166   jlong _value;
       
   167  public:
       
   168   ConstantLongValue(jlong value)       { _value = value; }
       
   169   jlong value() const                  { return _value;  }
       
   170   bool is_constant_long() const        { return true;    }
       
   171   bool equals(ScopeValue* other) const { return false;   }
       
   172 
       
   173   // Serialization of debugging information
       
   174   ConstantLongValue(DebugInfoReadStream* stream);
       
   175   void write_on(DebugInfoWriteStream* stream);
       
   176 
       
   177   // Printing
       
   178   void print_on(outputStream* st) const;
       
   179 };
       
   180 
       
   181 class ConstantDoubleValue: public ScopeValue {
       
   182  private:
       
   183   jdouble _value;
       
   184  public:
       
   185   ConstantDoubleValue(jdouble value)   { _value = value; }
       
   186   jdouble value() const                { return _value;  }
       
   187   bool is_constant_double() const      { return true;    }
       
   188   bool equals(ScopeValue* other) const { return false;   }
       
   189 
       
   190   // Serialization of debugging information
       
   191   ConstantDoubleValue(DebugInfoReadStream* stream);
       
   192   void write_on(DebugInfoWriteStream* stream);
       
   193 
       
   194   // Printing
       
   195   void print_on(outputStream* st) const;
       
   196 };
       
   197 
       
   198 // A ConstantOopWriteValue is created by the compiler to
       
   199 // be written as debugging information.
       
   200 
       
   201 class ConstantOopWriteValue: public ScopeValue {
       
   202  private:
       
   203   jobject _value;
       
   204  public:
       
   205   ConstantOopWriteValue(jobject value) { _value = value; }
       
   206   jobject value() const                { return _value;  }
       
   207   bool is_constant_oop() const         { return true;    }
       
   208   bool equals(ScopeValue* other) const { return false;   }
       
   209 
       
   210   // Serialization of debugging information
       
   211   void write_on(DebugInfoWriteStream* stream);
       
   212 
       
   213   // Printing
       
   214   void print_on(outputStream* st) const;
       
   215 };
       
   216 
       
   217 // A ConstantOopReadValue is created by the VM when reading
       
   218 // debug information
       
   219 
       
   220 class ConstantOopReadValue: public ScopeValue {
       
   221  private:
       
   222   Handle _value;
       
   223  public:
       
   224   Handle value() const                 { return _value;  }
       
   225   bool is_constant_oop() const         { return true;    }
       
   226   bool equals(ScopeValue* other) const { return false;   }
       
   227 
       
   228   // Serialization of debugging information
       
   229   ConstantOopReadValue(DebugInfoReadStream* stream);
       
   230   void write_on(DebugInfoWriteStream* stream);
       
   231 
       
   232   // Printing
       
   233   void print_on(outputStream* st) const;
       
   234 };
       
   235 
       
   236 // MonitorValue describes the pair used for monitor_enter and monitor_exit.
       
   237 
       
   238 class MonitorValue: public ResourceObj {
       
   239  private:
       
   240   ScopeValue* _owner;
       
   241   Location    _basic_lock;
       
   242   bool        _eliminated;
       
   243  public:
       
   244   // Constructor
       
   245   MonitorValue(ScopeValue* owner, Location basic_lock, bool eliminated = false);
       
   246 
       
   247   // Accessors
       
   248   ScopeValue*  owner()      const { return _owner; }
       
   249   Location     basic_lock() const { return _basic_lock;  }
       
   250   bool         eliminated() const { return _eliminated; }
       
   251 
       
   252   // Serialization of debugging information
       
   253   MonitorValue(DebugInfoReadStream* stream);
       
   254   void write_on(DebugInfoWriteStream* stream);
       
   255 
       
   256   // Printing
       
   257   void print_on(outputStream* st) const;
       
   258 };
       
   259 
       
   260 // DebugInfoReadStream specializes CompressedReadStream for reading
       
   261 // debugging information. Used by ScopeDesc.
       
   262 
       
   263 class DebugInfoReadStream : public CompressedReadStream {
       
   264  private:
       
   265   const CompiledMethod* _code;
       
   266   const CompiledMethod* code() const { return _code; }
       
   267   GrowableArray<ScopeValue*>* _obj_pool;
       
   268  public:
       
   269   DebugInfoReadStream(const CompiledMethod* code, int offset, GrowableArray<ScopeValue*>* obj_pool = NULL) :
       
   270     CompressedReadStream(code->scopes_data_begin(), offset) {
       
   271     _code = code;
       
   272     _obj_pool = obj_pool;
       
   273 
       
   274   } ;
       
   275 
       
   276   oop read_oop();
       
   277   Method* read_method() {
       
   278     Method* o = (Method*)(code()->metadata_at(read_int()));
       
   279     // is_metadata() is a faster check than is_metaspace_object()
       
   280     assert(o == NULL || o->is_metadata(), "meta data only");
       
   281     return o;
       
   282   }
       
   283   ScopeValue* read_object_value();
       
   284   ScopeValue* get_cached_object();
       
   285   // BCI encoding is mostly unsigned, but -1 is a distinguished value
       
   286   int read_bci() { return read_int() + InvocationEntryBci; }
       
   287 };
       
   288 
       
   289 // DebugInfoWriteStream specializes CompressedWriteStream for
       
   290 // writing debugging information. Used by ScopeDescRecorder.
       
   291 
       
   292 class DebugInfoWriteStream : public CompressedWriteStream {
       
   293  private:
       
   294   DebugInformationRecorder* _recorder;
       
   295   DebugInformationRecorder* recorder() const { return _recorder; }
       
   296  public:
       
   297   DebugInfoWriteStream(DebugInformationRecorder* recorder, int initial_size);
       
   298   void write_handle(jobject h);
       
   299   void write_bci(int bci) { write_int(bci - InvocationEntryBci); }
       
   300 
       
   301   void write_metadata(Metadata* m);
       
   302 };
       
   303 
       
   304 #endif // SHARE_VM_CODE_DEBUGINFO_HPP