--- old/src/share/vm/opto/parse3.cpp 2016-12-20 14:34:23.639342920 +0100 +++ new/src/share/vm/opto/parse3.cpp 2016-12-20 14:34:23.311342935 +0100 @@ -151,7 +151,7 @@ ciField* field = iter().get_field(will_link); BasicType bt = field->layout_type(); ValueTypeNode* vt = pop()->as_ValueType(); - Node* value = vt->get_field_value_by_offset(field->offset()); + Node* value = vt->field_value_by_offset(field->offset()); push_node(bt, value); } @@ -522,3 +522,53 @@ // - Make a fast path for small multi-arrays. (W/ implicit init. loops.) // - Issue CastII against length[*] values, to TypeInt::POS. } + +void Parse::do_vbox() { + // Obtain a value type from the top of the stack + ValueTypeNode* vt = pop()->as_ValueType(); + + // Obtain types + bool will_link; + ciValueKlass* dvt_klass = gvn().type(vt)->is_valuetype()->value_klass(); + ciInstanceKlass* vcc_klass = iter().get_klass(will_link)->as_instance_klass(); + guarantee(will_link, "value-capable class must be loaded"); + + kill_dead_locals(); + + // TODO: Generate all (or some) of the following checks + // (1) if target is not an value-capable instance, throw ClassCastException + // (2) if source is not a value type instance, throw ClassCastException + // (3) if target type is not a value type derived from source + + // create new object + Node* kls = makecon(TypeKlassPtr::make(vcc_klass)); + Node* obj = new_instance(kls); + + // Store all field values to the newly created object. + // The code below relies on the assumption that the VCC has the + // same memory layout as the derived value type. + // TODO: Once the layout of the two is not the same, update code below. + vt->store_values(this, vcc_klass, obj); + + // Push the new object onto the stack + push(obj); +} + +void Parse::do_vunbox() { + // Obtain object from the top of the stack + Node* obj = pop(); + + // Obtain types + bool will_link; + ciInstanceKlass* vcc_klass = gvn().type(obj)->is_oopptr()->klass()->as_instance_klass(); + ciValueKlass* dvt_klass = iter().get_klass(will_link)->as_value_klass(); + guarantee(will_link, "derived value type must be loaded"); + + // TOOD: Generate all the checks. Similar to vbox + + // Create a value type node with the corresponding type + Node* vt = ValueTypeNode::make(gvn(), dvt_klass, map()->memory(), vcc_klass, obj, dvt_klass->first_field_offset()); + + // Push the value type onto the stack + push(vt); +}