< prev index next >

src/hotspot/share/prims/vectorSupport.cpp

Print this page




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jni.h"
  27 #include "jvm.h"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "code/location.hpp"
  30 #include "prims/vectorSupport.hpp"
  31 #include "runtime/fieldDescriptor.inline.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/interfaceSupport.inline.hpp"
  34 #include "runtime/jniHandles.inline.hpp"
  35 #include "runtime/stackValue.hpp"
  36 
  37 #ifdef COMPILER2
  38 #include "opto/matcher.hpp" // Matcher::max_vector_size(BasicType)
  39 #endif // COMPILER2
  40 







































































































































































  41 #ifdef COMPILER2
  42 int VectorSupport::vop2ideal(jint id, BasicType bt) {
  43   VectorOperation vop = (VectorOperation)id;
  44   switch (vop) {
  45     case VECTOR_OP_ADD: {
  46       switch (bt) {
  47         case T_BYTE:   // fall-through
  48         case T_SHORT:  // fall-through
  49         case T_INT:    return Op_AddI;
  50         case T_LONG:   return Op_AddL;
  51         case T_FLOAT:  return Op_AddF;
  52         case T_DOUBLE: return Op_AddD;
  53         default: fatal("ADD: %s", type2name(bt));
  54       }
  55       break;
  56     }
  57     case VECTOR_OP_SUB: {
  58       switch (bt) {
  59         case T_BYTE:   // fall-through
  60         case T_SHORT:  // fall-through




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jni.h"
  27 #include "jvm.h"
  28 #include "classfile/javaClasses.inline.hpp"
  29 #include "code/location.hpp"
  30 #include "prims/vectorSupport.hpp"
  31 #include "runtime/fieldDescriptor.inline.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/interfaceSupport.inline.hpp"
  34 #include "runtime/jniHandles.inline.hpp"
  35 #include "runtime/stackValue.hpp"
  36 
  37 #ifdef COMPILER2
  38 #include "opto/matcher.hpp" // Matcher::max_vector_size(BasicType)
  39 #endif // COMPILER2
  40 
  41 bool VectorSupport::is_vector(Klass* klass) {
  42   return klass->is_subclass_of(SystemDictionary::vector_VectorPayload_klass());
  43 }
  44 
  45 bool VectorSupport::is_vector_mask(Klass* klass) {
  46   return klass->is_subclass_of(SystemDictionary::vector_VectorMask_klass());
  47 }
  48 
  49 bool VectorSupport::is_vector_shuffle(Klass* klass) {
  50   return klass->is_subclass_of(SystemDictionary::vector_VectorShuffle_klass());
  51 }
  52 
  53 BasicType VectorSupport::klass2bt(InstanceKlass* ik) {
  54   assert(ik->is_subclass_of(SystemDictionary::vector_VectorPayload_klass()), "%s not a VectorPayload", ik->name()->as_C_string());
  55   fieldDescriptor fd; // find_field initializes fd if found
  56   // static final Class<?> ETYPE;
  57   Klass* holder = ik->find_field(vmSymbols::ETYPE_name(), vmSymbols::class_signature(), &fd);
  58 
  59   assert(holder != NULL, "sanity");
  60   assert(fd.is_static(), "");
  61   assert(fd.offset() > 0, "");
  62 
  63   if (is_vector_shuffle(ik)) {
  64     return T_BYTE;
  65   } else { // vector and mask
  66     oop value = ik->java_mirror()->obj_field(fd.offset());
  67     BasicType elem_bt = java_lang_Class::as_BasicType(value);
  68     return elem_bt;
  69   }
  70 }
  71 
  72 jint VectorSupport::klass2length(InstanceKlass* ik) {
  73   fieldDescriptor fd; // find_field initializes fd if found
  74   // static final int VLENGTH;
  75   Klass* holder = ik->find_field(vmSymbols::VLENGTH_name(), vmSymbols::int_signature(), &fd);
  76 
  77   assert(holder != NULL, "sanity");
  78   assert(fd.is_static(), "");
  79   assert(fd.offset() > 0, "");
  80 
  81   jint vlen = ik->java_mirror()->int_field(fd.offset());
  82   assert(vlen > 0, "");
  83   return vlen;
  84 }
  85 
  86 void VectorSupport::init_vector_array(typeArrayOop arr, BasicType elem_bt, int num_elem, address value_addr) {
  87   int elem_size = type2aelembytes(elem_bt);
  88   for (int i = 0; i < num_elem; i++) {
  89     switch (elem_bt) {
  90       case T_BYTE: {
  91         jbyte elem_value = *(jbyte*) (value_addr + i * elem_size);
  92         arr->byte_at_put(i, elem_value);
  93         break;
  94       }
  95       case T_SHORT: {
  96         jshort elem_value = *(jshort*) (value_addr + i * elem_size);
  97         arr->short_at_put(i, elem_value);
  98         break;
  99       }
 100       case T_INT: {
 101         jint elem_value = *(jint*) (value_addr + i * elem_size);
 102         arr->int_at_put(i, elem_value);
 103         break;
 104       }
 105       case T_LONG: {
 106         jlong elem_value = *(jlong*) (value_addr + i * elem_size);
 107         arr->long_at_put(i, elem_value);
 108         break;
 109       }
 110       case T_FLOAT: {
 111         jfloat elem_value = *(jfloat*) (value_addr + i * elem_size);
 112         arr->float_at_put(i, elem_value);
 113         break;
 114       }
 115       case T_DOUBLE: {
 116         jdouble elem_value = *(jdouble*) (value_addr + i * elem_size);
 117         arr->double_at_put(i, elem_value);
 118         break;
 119       }
 120       default:
 121         fatal("unsupported: %s", type2name(elem_bt));
 122     }
 123   }
 124 }
 125 
 126 void VectorSupport::init_mask_array(typeArrayOop arr, BasicType elem_bt, int num_elem, address value_addr) {
 127   int elem_size = type2aelembytes(elem_bt);
 128 
 129   for (int i = 0; i < num_elem; i++) {
 130     switch (elem_bt) {
 131       case T_BYTE: {
 132         jbyte elem_value = *(jbyte*) (value_addr + i * elem_size);
 133         arr->bool_at_put(i, elem_value != 0);
 134         break;
 135       }
 136       case T_SHORT: {
 137         jshort elem_value = *(jshort*) (value_addr + i * elem_size);
 138         arr->bool_at_put(i, elem_value != 0);
 139         break;
 140       }
 141       case T_INT:   // fall-through
 142       case T_FLOAT: {
 143         jint elem_value = *(jint*) (value_addr + i * elem_size);
 144         arr->bool_at_put(i, elem_value != 0);
 145         break;
 146       }
 147       case T_LONG: // fall-through
 148       case T_DOUBLE: {
 149         jlong elem_value = *(jlong*) (value_addr + i * elem_size);
 150         arr->bool_at_put(i, elem_value != 0);
 151         break;
 152       }
 153       default:
 154         fatal("unsupported: %s", type2name(elem_bt));
 155     }
 156   }
 157 }
 158 
 159 oop VectorSupport::allocate_vector_payload_helper(InstanceKlass* ik, BasicType elem_bt, int num_elem, address value_addr, TRAPS) {
 160 
 161   bool is_mask = is_vector_mask(ik);
 162 
 163   // On-heap vector values are represented as primitive arrays.
 164   TypeArrayKlass* tak = TypeArrayKlass::cast(Universe::typeArrayKlassObj(is_mask ? T_BOOLEAN : elem_bt));
 165 
 166   typeArrayOop arr = tak->allocate(num_elem, CHECK_NULL); // safepoint
 167 
 168   if (is_mask) {
 169     init_mask_array(arr, elem_bt, num_elem, value_addr);
 170   } else {
 171     init_vector_array(arr, elem_bt, num_elem, value_addr);
 172   }
 173   return arr;
 174 }
 175 
 176 oop VectorSupport::allocate_vector(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, ObjectValue* ov, TRAPS) {
 177   assert(is_vector(ik), "%s not a vector", ik->name()->as_C_string());
 178   assert(ov->field_size() == 1, "%s not a vector", ik->name()->as_C_string());
 179 
 180   // Vector value in an aligned adjacent tuple (1, 2, 4, 8, or 16 slots).
 181   LocationValue* loc_value = ov->field_at(0)->as_LocationValue();
 182 
 183   BasicType elem_bt = klass2bt(ik);
 184   int num_elem = klass2length(ik);
 185 
 186   Handle vbox = ik->allocate_instance_handle(CHECK_NULL);
 187 
 188   Location loc = loc_value->location();
 189 
 190   oop payload = NULL;
 191   if (loc.type() == Location::vector) {
 192     address value_addr = loc.is_register()
 193         // Value was in a callee-save register
 194         ? reg_map->location(VMRegImpl::as_VMReg(loc.register_number()))
 195         // Else value was directly saved on the stack. The frame's original stack pointer,
 196         // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
 197         : ((address)fr->unextended_sp()) + loc.stack_offset();
 198     payload = allocate_vector_payload_helper(ik, elem_bt, num_elem, value_addr, CHECK_NULL); // safepoint
 199   } else {
 200     // assert(false, "interesting");
 201     StackValue* value = StackValue::create_stack_value(fr, reg_map, loc_value);
 202     payload = value->get_obj()();
 203   }
 204   vector_VectorPayload::set_payload(vbox(), payload);
 205   return vbox();
 206 }
 207 
 208 #ifdef COMPILER2
 209 int VectorSupport::vop2ideal(jint id, BasicType bt) {
 210   VectorOperation vop = (VectorOperation)id;
 211   switch (vop) {
 212     case VECTOR_OP_ADD: {
 213       switch (bt) {
 214         case T_BYTE:   // fall-through
 215         case T_SHORT:  // fall-through
 216         case T_INT:    return Op_AddI;
 217         case T_LONG:   return Op_AddL;
 218         case T_FLOAT:  return Op_AddF;
 219         case T_DOUBLE: return Op_AddD;
 220         default: fatal("ADD: %s", type2name(bt));
 221       }
 222       break;
 223     }
 224     case VECTOR_OP_SUB: {
 225       switch (bt) {
 226         case T_BYTE:   // fall-through
 227         case T_SHORT:  // fall-through


< prev index next >