1 /*
   2  * Copyright (c) 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_OPTO_VALUETYPENODE_HPP
  26 #define SHARE_VM_OPTO_VALUETYPENODE_HPP
  27 
  28 #include "opto/node.hpp"
  29 #include "opto/connode.hpp"
  30 
  31 class GraphKit;
  32 
  33 // TODO add comment
  34 class ValueTypeNode : public TypeNode {
  35 private:
  36   ValueTypeNode(const TypeValueType* t, Node* oop)
  37     : TypeNode(t, Values + t->value_klass()->field_count()) {
  38     init_class_id(Class_ValueType);
  39     init_req(Oop, oop);
  40   }
  41   ciValueKlass* get_value_klass() const { return type()->is_valuetype()->value_klass(); }
  42 
  43   enum { Control,   // Control input
  44          Oop,       // Oop of TypeValueTypePtr
  45          Values     // Nodes corresponding to field values
  46   };
  47 
  48 public:
  49   // Create a new ValueTypeNode with uninitialized values
  50   static Node* make(PhaseGVN& gvn, ciValueKlass* klass);
  51   // Create a new ValueTypeNode and load its values from memory
  52   static Node* make(PhaseGVN& gvn, Node* mem, Node* oop);
  53 
  54   // Stores the value type to memory if not yet allocated and returns the oop
  55   Node* store_to_memory(GraphKit* kit);
  56 
  57   // Get oop for heap allocated value type (may be TypePtr::NULL_PTR)
  58   Node* get_oop() const    { return in(Oop); }
  59   void  set_oop(Node* oop) { set_req(Oop, oop); }
  60 
  61   // Value type fields
  62   uint      field_count() const { return req() - Values; }
  63   Node*     get_field_value(uint index) const;
  64   Node*     get_field_value_by_offset(int field_offset) const;
  65   void      set_field_value(uint index, Node* value);
  66   int       get_field_offset(uint index) const;
  67   BasicType get_field_type(uint index) const;
  68 
  69   // Replace ValueTypeNodes in debug info at safepoints with SafePointScalarObjectNodes
  70   void make_scalar_in_safepoints(Compile* C);
  71 
  72   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
  73   virtual int Opcode() const;
  74 
  75 #ifndef PRODUCT
  76   virtual void dump_spec(outputStream* st) const;
  77 #endif
  78 };
  79 
  80 #endif // SHARE_VM_OPTO_VALUETYPENODE_HPP