Skip to content

Commit

Permalink
8311610: [lworld+vector] Clean-up of vector allocation in class Vecto…
Browse files Browse the repository at this point in the history
…rSupport

Reviewed-by: jbhateja
  • Loading branch information
Xiaohong Gong authored and Jatin Bhateja committed Jul 12, 2023
1 parent bb13513 commit 656a4ba
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 329 deletions.
49 changes: 33 additions & 16 deletions src/hotspot/share/opto/callnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,28 +507,45 @@ void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st)
Node* init_node = mcall->in(first_ind++);
if (!init_node->is_top()) {
st->print(" [is_init");
format_helper(regalloc, st, init_node, ":", -1, nullptr);
format_helper(regalloc, st, init_node, ":", -2, nullptr);
}

Node* larval_node = mcall->in(first_ind++);
assert(larval_node != NULL && larval_node->is_Con(), "is_larval node not found");
st->print(" [is_larval");
format_helper(regalloc, st, larval_node, ":", -1, NULL);
}
Node* fld_node = mcall->in(first_ind);

ciField* cifield;
if (iklass != nullptr) {
st->print(" [");
cifield = iklass->nonstatic_field_at(0);
cifield->print_name_on(st);
format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
} else {
format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
}
for (uint j = 1; j < nf; j++) {
fld_node = mcall->in(first_ind+j);
if (iklass != nullptr) {
st->print(", [");
cifield = iklass->nonstatic_field_at(j);
uint sec_fields_count = 0;
for (uint j = 0; j < nf; j++) {
Node* fld_node = mcall->in(first_ind + j);
if (iklass != NULL) {
st->print(" [");
cifield = iklass->nonstatic_field_at(j - sec_fields_count);
cifield->print_name_on(st);
format_helper(regalloc, st, fld_node, ":", j, &scobjs);
sec_fields_count = 0;
if (cifield->is_multifield_base() && !fld_node->bottom_type()->isa_vect()) {
sec_fields_count = cifield->secondary_fields_count() - 1;
for (uint f = 0; f < sec_fields_count; f++) {
st->print(" [");
fld_node = mcall->in(first_ind + j + f + 1);
ciField* sec_field = static_cast<ciMultiField*>(cifield)->secondary_field_at(f);
sec_field->print_name_on(st);
format_helper(regalloc, st, fld_node, ":", j + f + 1, &scobjs);
if (f < sec_fields_count - 1) {
st->print(",");
}
}
j += sec_fields_count;
}
} else {
format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
format_helper(regalloc, st, fld_node, " [", j, &scobjs);
}

if (j < nf - 1) {
st->print(",");
}
}
}
Expand Down
248 changes: 0 additions & 248 deletions src/hotspot/share/prims/vectorSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,259 +77,11 @@ bool VectorSupport::is_vector_payload_mf(Klass* klass) {
return klass->is_subclass_of(vmClasses::vector_VectorPayloadMF_klass());
}

bool VectorSupport::is_vector_mask(Klass* klass) {
return klass->is_subclass_of(vmClasses::vector_VectorMask_klass());
}

bool VectorSupport::skip_value_scalarization(Klass* klass) {
return VectorSupport::is_vector(klass) ||
VectorSupport::is_vector_payload_mf(klass);
}

BasicType VectorSupport::klass2bt(InstanceKlass* ik) {
assert(ik->is_subclass_of(vmClasses::vector_VectorPayload_klass()), "%s not a VectorPayload", ik->name()->as_C_string());
fieldDescriptor fd; // find_field initializes fd if found
// static final Class<?> ETYPE;
Klass* holder = ik->find_field(vmSymbols::ETYPE_name(), vmSymbols::class_signature(), &fd);

assert(holder != nullptr, "sanity");
assert(fd.is_static(), "");
assert(fd.offset() > 0, "");

if (is_vector_mask(ik)) {
return T_BOOLEAN;
} else { // vector and mask
oop value = ik->java_mirror()->obj_field(fd.offset());
BasicType elem_bt = java_lang_Class::as_BasicType(value);
return elem_bt;
}
}

jint VectorSupport::klass2length(InstanceKlass* ik) {
fieldDescriptor fd; // find_field initializes fd if found
// static final int VLENGTH;
Klass* holder = ik->find_field(vmSymbols::VLENGTH_name(), vmSymbols::int_signature(), &fd);

assert(holder != nullptr, "sanity");
assert(fd.is_static(), "");
assert(fd.offset() > 0, "");

jint vlen = ik->java_mirror()->int_field(fd.offset());
assert(vlen > 0, "");
return vlen;
}

#ifdef COMPILER2
Handle VectorSupport::allocate_vector_payload_helper(InstanceKlass* ik, int num_elem, BasicType elem_bt, int larval, TRAPS) {
assert(ik->is_inline_klass(), "");
instanceOop obj = InlineKlass::cast(ik)->allocate_instance(THREAD);
if (larval) obj->set_mark(obj->mark().enter_larval_state());

fieldDescriptor fd;
Klass* def = ik->find_field(vmSymbols::mfield_name(), vmSymbols::type_signature(elem_bt), false, &fd);
assert(fd.is_multifield_base() && fd.secondary_fields_count(fd.index()) == num_elem, "");
return Handle(THREAD, obj);
}

Symbol* VectorSupport::get_vector_payload_field_signature(BasicType elem_bt, int num_elem) {
switch(elem_bt) {
case T_BOOLEAN:
switch(num_elem) {
case 1: return vmSymbols::vector_VectorPayloadMF8Z_signature();
case 2: return vmSymbols::vector_VectorPayloadMF16Z_signature();
case 4: return vmSymbols::vector_VectorPayloadMF32Z_signature();
case 8: return vmSymbols::vector_VectorPayloadMF64Z_signature();
case 16: return vmSymbols::vector_VectorPayloadMF128Z_signature();
case 32: return vmSymbols::vector_VectorPayloadMF256Z_signature();
case 64: return vmSymbols::vector_VectorPayloadMF512Z_signature();
default: ShouldNotReachHere();
} break;
case T_BYTE:
switch(num_elem) {
case 1: return vmSymbols::vector_VectorPayloadMF8B_signature();
case 2: return vmSymbols::vector_VectorPayloadMF16B_signature();
case 4: return vmSymbols::vector_VectorPayloadMF32B_signature();
case 8: return vmSymbols::vector_VectorPayloadMF64B_signature();
case 16: return vmSymbols::vector_VectorPayloadMF128B_signature();
case 32: return vmSymbols::vector_VectorPayloadMF256B_signature();
case 64: return vmSymbols::vector_VectorPayloadMF512B_signature();
default: ShouldNotReachHere();
} break;
case T_SHORT:
switch(num_elem) {
case 4: return vmSymbols::vector_VectorPayloadMF64S_signature();
case 8: return vmSymbols::vector_VectorPayloadMF128S_signature();
case 16: return vmSymbols::vector_VectorPayloadMF256S_signature();
case 32: return vmSymbols::vector_VectorPayloadMF512S_signature();
default: ShouldNotReachHere();
} break;
case T_INT:
switch(num_elem) {
case 2: return vmSymbols::vector_VectorPayloadMF64I_signature();
case 4: return vmSymbols::vector_VectorPayloadMF128I_signature();
case 8: return vmSymbols::vector_VectorPayloadMF256I_signature();
case 16: return vmSymbols::vector_VectorPayloadMF512I_signature();
default: ShouldNotReachHere();
} break;
case T_LONG:
switch(num_elem) {
case 1: return vmSymbols::vector_VectorPayloadMF64L_signature();
case 2: return vmSymbols::vector_VectorPayloadMF128L_signature();
case 4: return vmSymbols::vector_VectorPayloadMF256L_signature();
case 8: return vmSymbols::vector_VectorPayloadMF512L_signature();
default: ShouldNotReachHere();
} break;
case T_FLOAT:
switch(num_elem) {
case 2: return vmSymbols::vector_VectorPayloadMF64F_signature();
case 4: return vmSymbols::vector_VectorPayloadMF128F_signature();
case 8: return vmSymbols::vector_VectorPayloadMF256F_signature();
case 16: return vmSymbols::vector_VectorPayloadMF512F_signature();
default: ShouldNotReachHere();
} break;
case T_DOUBLE:
switch(num_elem) {
case 1: return vmSymbols::vector_VectorPayloadMF64D_signature();
case 2: return vmSymbols::vector_VectorPayloadMF128D_signature();
case 4: return vmSymbols::vector_VectorPayloadMF256D_signature();
case 8: return vmSymbols::vector_VectorPayloadMF512D_signature();
default: ShouldNotReachHere();
} break;
default:
ShouldNotReachHere();
}
return NULL;
}

InstanceKlass* VectorSupport::get_vector_payload_klass(BasicType elem_bt, int num_elem) {
switch(elem_bt) {
case T_BOOLEAN:
switch(num_elem) {
case 1: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF8Z_klass));
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF16Z_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF32Z_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64Z_klass));
case 16: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128Z_klass));
case 32: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256Z_klass));
case 64: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512Z_klass));
default: ShouldNotReachHere();
} break;
case T_BYTE:
switch(num_elem) {
case 1: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF8B_klass));
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF16B_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF32B_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64B_klass));
case 16: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128B_klass));
case 32: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256B_klass));
case 64: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512B_klass));
default: ShouldNotReachHere();
} break;
case T_SHORT:
switch(num_elem) {
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64S_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128S_klass));
case 16: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256S_klass));
case 32: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512S_klass));
default: ShouldNotReachHere();
} break;
case T_INT:
switch(num_elem) {
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64I_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128I_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256I_klass));
case 16: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512I_klass));
default: ShouldNotReachHere();
} break;
case T_LONG:
switch(num_elem) {
case 1: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64L_klass));
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128L_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256L_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512L_klass));
default: ShouldNotReachHere();
} break;
case T_FLOAT:
switch(num_elem) {
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64F_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128F_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256F_klass));
case 16: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512F_klass));
default: ShouldNotReachHere();
} break;
case T_DOUBLE:
switch(num_elem) {
case 1: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF64D_klass));
case 2: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF128D_klass));
case 4: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF256D_klass));
case 8: return vmClasses::klass_at(VM_CLASS_ID(vector_VectorPayloadMF512D_klass));
default: ShouldNotReachHere();
} break;
default:
ShouldNotReachHere();
}
return NULL;
}

Handle VectorSupport::allocate_vector_payload(InstanceKlass* ik, int num_elem, BasicType elem_bt, frame* fr, RegisterMap* reg_map, ObjectValue* ov, TRAPS) {
intptr_t is_larval = StackValue::create_stack_value(fr, reg_map, ov->is_larval())->get_int();
jint larval = (jint)*((jint*)&is_larval);
// Vector payload value in an aligned adjacent tuple (8, 16, 32 or 64 bytes).
return allocate_vector_payload_helper(ik, num_elem, elem_bt, larval, THREAD); // safepoint
}

instanceOop VectorSupport::allocate_vector_payload(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, ObjectValue* ov, TRAPS) {
assert(is_vector_payload_mf(ik), "%s not a vector payload", ik->name()->as_C_string());
assert(ik->is_inline_klass(), "");

int num_elem = 0;
BasicType elem_bt = T_ILLEGAL;
for (JavaFieldStream fs(ik); !fs.done(); fs.next()) {
fieldDescriptor& fd = fs.field_descriptor();
if (fd.is_multifield_base()) {
elem_bt = fd.field_type();
num_elem = fd.secondary_fields_count(fd.index());
break;
}
}
assert(num_elem != 0, "");
Handle payload_instance = VectorSupport::allocate_vector_payload(ik, num_elem, elem_bt, fr, reg_map, ov, CHECK_NULL);
return (instanceOop)payload_instance();
}

instanceOop VectorSupport::allocate_vector(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, ObjectValue* ov, TRAPS) {
assert(is_vector(ik), "%s not a vector", ik->name()->as_C_string());
assert(ik->is_inline_klass(), "");

int num_elem = klass2length(ik);
BasicType elem_bt = klass2bt(ik);

// On-heap vector values are represented as primitive class instances with a multi-field payload.
InstanceKlass* payload_class = get_vector_payload_klass(elem_bt, num_elem);
assert(payload_class->is_inline_klass(), "");

Handle payload_instance = VectorSupport::allocate_vector_payload(payload_class, num_elem, elem_bt, fr, reg_map, ov, CHECK_NULL);

Deoptimization::reassign_fields_by_klass(payload_class, fr, reg_map, ov, 0, payload_instance(), true, 0, CHECK_NULL);

instanceOop vbox = ik->allocate_instance(THREAD);
Handle vbox_h = Handle(THREAD, vbox);

fieldDescriptor fd;
Symbol* payload_sig = VectorSupport::get_vector_payload_field_signature(elem_bt, num_elem);
Klass* def = ik->find_field(vmSymbols::payload_name(), payload_sig, false, &fd);
assert(def != NULL, "");

if (fd.is_inlined()) {
InlineKlass* field_ik = InlineKlass::cast(ik->get_inline_type_field_klass(fd.index()));
field_ik->write_inlined_field(vbox_h(), fd.offset(), payload_instance(), THREAD);
} else {
vbox_h()->obj_field_put(fd.offset(), payload_instance());
}
return vbox;
}
#endif // COMPILER2

#ifdef COMPILER2
int VectorSupport::vop2ideal(jint id, BasicType bt) {
VectorOperation vop = (VectorOperation)id;
Expand Down
18 changes: 0 additions & 18 deletions src/hotspot/share/prims/vectorSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ extern "C" {
}

class VectorSupport : AllStatic {
private:

#ifdef COMPILER2
static Handle allocate_vector_payload_helper(InstanceKlass* ik, int num_elem, BasicType elem_bt, int larval, TRAPS);
static Handle allocate_vector_payload(InstanceKlass* ik, int num_elem, BasicType elem_bt, frame* fr, RegisterMap* reg_map, ObjectValue* ov, TRAPS);
static InstanceKlass* get_vector_payload_klass(BasicType elem_bt, int num_elem);
static Symbol* get_vector_payload_field_signature(BasicType elem_bt, int num_elem);
#endif // COMPILER2

static BasicType klass2bt(InstanceKlass* ik);
static jint klass2length(InstanceKlass* ik);

public:

Expand Down Expand Up @@ -146,15 +135,8 @@ class VectorSupport : AllStatic {

static int vop2ideal(jint vop, BasicType bt);

#ifdef COMPILER2
static instanceOop allocate_vector(InstanceKlass* holder, frame* fr, RegisterMap* reg_map, ObjectValue* sv, TRAPS);
static instanceOop allocate_vector_payload(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, ObjectValue* sv, TRAPS);
#endif // COMPILER2

static bool is_vector(Klass* klass);
static bool is_vector_payload_mf(Klass* klass);
static bool is_vector_mask(Klass* klass);
static bool is_vector_shuffle(Klass* klass);
static bool skip_value_scalarization(Klass* klass);
};
#endif // SHARE_PRIMS_VECTORSUPPORT_HPP
Loading

0 comments on commit 656a4ba

Please sign in to comment.