1 /*
   2  * Copyright (c) 1997, 2016, 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_RUNTIME_VFRAME_HP_HPP
  26 #define SHARE_VM_RUNTIME_VFRAME_HP_HPP
  27 
  28 #include "runtime/vframe.hpp"
  29 
  30 class compiledVFrame: public javaVFrame {
  31  public:
  32   // JVM state
  33   Method*                      method()             const;
  34   int                          bci()                const;
  35   bool                         should_reexecute()   const;
  36   StackValueCollection*        locals()             const;
  37   StackValueCollection*        expressions()        const;
  38   GrowableArray<MonitorInfo*>* monitors()           const;
  39   int                          vframe_id()          const { return _vframe_id; }
  40 
  41   void set_locals(StackValueCollection* values) const;
  42 
  43   // Virtuals defined in vframe
  44   bool is_compiled_frame() const { return true; }
  45   vframe* sender() const;
  46   bool is_top() const;
  47 
  48   // Casting
  49   static compiledVFrame* cast(vframe* vf) {
  50     assert(vf == NULL || vf->is_compiled_frame(), "must be compiled frame");
  51     return (compiledVFrame*) vf;
  52   }
  53 
  54   void update_deferred_value(BasicType type, int index, jvalue value);
  55 
  56  public:
  57   // Constructors
  58   compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, CompiledMethod* nm);
  59 
  60   // Update a local in a compiled frame. Update happens when deopt occurs
  61   void update_local(BasicType type, int index, jvalue value);
  62 
  63   // Update an expression stack value in a compiled frame. Update happens when deopt occurs
  64   void update_stack(BasicType type, int index, jvalue value);
  65 
  66   // Update a lock value in a compiled frame. Update happens when deopt occurs
  67   void update_monitor(int index, MonitorInfo* value);
  68 
  69   // Returns the active nmethod
  70   CompiledMethod*  code() const;
  71 
  72   // Returns the scopeDesc
  73   ScopeDesc* scope() const { return _scope; }
  74 
  75   // Returns SynchronizationEntryBCI or bci() (used for synchronization)
  76   int raw_bci() const;
  77 
  78  protected:
  79   ScopeDesc* _scope;
  80   int _vframe_id;
  81 
  82   //StackValue resolve(ScopeValue* sv) const;
  83   BasicLock* resolve_monitor_lock(Location location) const;
  84   StackValue *create_stack_value(ScopeValue *sv) const;
  85 
  86  private:
  87   compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, ScopeDesc* scope, int vframe_id);
  88 
  89 #ifndef PRODUCT
  90  public:
  91   void verify() const;
  92 #endif
  93 };
  94 
  95 // In order to implement set_locals for compiled vframes we must
  96 // store updated locals in a data structure that contains enough
  97 // information to recognize equality with a vframe and to store
  98 // any updated locals.
  99 
 100 class jvmtiDeferredLocalVariable;
 101 class jvmtiDeferredLocalVariableSet : public CHeapObj<mtCompiler> {
 102   friend class compiledVFrame;
 103 
 104 private:
 105 
 106   Method* _method;
 107   int       _bci;
 108   intptr_t* _id;
 109   int _vframe_id;
 110   GrowableArray<jvmtiDeferredLocalVariable*>* _locals;
 111 
 112   void                              update_value(StackValueCollection* locals, BasicType type, int index, jvalue value);
 113 
 114   void                              set_value_at(int idx, BasicType typ, jvalue val);
 115 
 116  public:
 117   // JVM state
 118   Method*                           method()         const  { return _method; }
 119   int                               bci()            const  { return _bci; }
 120   intptr_t*                         id()             const  { return _id; }
 121   int                               vframe_id()      const  { return _vframe_id; }
 122 
 123   void                              update_locals(StackValueCollection* locals);
 124   void                              update_stack(StackValueCollection* locals);
 125   void                              update_monitors(GrowableArray<MonitorInfo*>* monitors);
 126 
 127   // Does the vframe match this jvmtiDeferredLocalVariableSet
 128   bool                              matches(const vframe* vf);
 129   // GC
 130   void                              oops_do(OopClosure* f);
 131 
 132   // constructor
 133   jvmtiDeferredLocalVariableSet(Method* method, int bci, intptr_t* id, int vframe_id);
 134 
 135   // destructor
 136   ~jvmtiDeferredLocalVariableSet();
 137 
 138 
 139 };
 140 
 141 class jvmtiDeferredLocalVariable : public CHeapObj<mtCompiler> {
 142   public:
 143 
 144     jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value);
 145 
 146     BasicType type(void)                   { return _type; }
 147     int index(void)                        { return _index; }
 148     jvalue value(void)                     { return _value; }
 149     // Only mutator is for value as only it can change
 150     void set_value(jvalue value)           { _value = value; }
 151     // For gc
 152     oop* oop_addr(void)                    { return (oop*) &_value.l; }
 153 
 154   private:
 155 
 156     BasicType         _type;
 157     jvalue            _value;
 158     int               _index;
 159 
 160 };
 161 
 162 #endif // SHARE_VM_RUNTIME_VFRAME_HP_HPP