< prev index next >

src/hotspot/share/c1/c1_GraphBuilder.cpp

Print this page


1839         assert(field->type()->is_valuetype(), "Sanity check");
1840         ciValueKlass* value_klass = field->type()->as_value_klass();
1841         int flattening_offset = field->offset() - value_klass->first_field_offset();
1842         copy_value_content(value_klass, val, value_klass->first_field_offset(), obj, field->offset(),
1843                    state_before, needs_patching);
1844       }
1845       break;
1846     }
1847     default:
1848       ShouldNotReachHere();
1849       break;
1850   }
1851 }
1852 
1853 // Baseline version of withfield, allocate every time
1854 void GraphBuilder::withfield(int field_index)
1855 {
1856   bool will_link;
1857   ciField* field_modify = stream()->get_field(will_link);
1858   ciInstanceKlass* holder = field_modify->holder();
1859   assert(holder->is_valuetype(), "must be a value klass");
1860   BasicType field_type = field_modify->type()->basic_type();
1861   ValueType* type = as_ValueType(field_type);
1862 
1863   // call will_link again to determine if the field is valid.
1864   const bool needs_patching = !holder->is_loaded() ||
1865                               !field_modify->will_link(method(), Bytecodes::_withfield) ||
1866                               PatchALot;
1867 
1868 
1869   scope()->set_wrote_final();
1870   scope()->set_wrote_fields();
1871 
1872   const int offset = !needs_patching ? field_modify->offset() : -1;



1873   Value val = pop(type);
1874   Value obj = apop();
1875 


1876   ValueStack* state_before = copy_state_for_exception();
1877 




1878   NewValueTypeInstance* new_instance = new NewValueTypeInstance(holder->as_value_klass(), state_before, false);
1879   _memory->new_instance(new_instance);
1880   apush(append_split(new_instance));
1881 
1882   for (int i = 0; i < holder->nof_nonstatic_fields(); i++) {
1883     ciField* field = holder->nonstatic_field_at(i);
1884     int off = field->offset();
1885 
1886     if (field->offset() != offset) {
1887       if (field->is_flattened()) {
1888         assert(field->type()->is_valuetype(), "Sanity check");
1889         assert(field->type()->is_valuetype(), "Only value types can be flattened");
1890         ciValueKlass* vk = field->type()->as_value_klass();
1891         copy_value_content(vk, obj, off, new_instance, vk->first_field_offset(), state_before, needs_patching);
1892       } else {
1893         // Only load those fields who are not modified
1894         LoadField* load = new LoadField(obj, off, field, false, state_before, needs_patching);
1895         Value replacement = append(load);
1896         StoreField* store = new StoreField(new_instance, off, field, replacement, false, state_before, needs_patching);
1897         append(store);


2284     }
2285   }
2286   if (profile_return() && result_type->is_object_kind()) {
2287     profile_return_type(result, target);
2288   }
2289 }
2290 
2291 
2292 void GraphBuilder::new_instance(int klass_index) {
2293   ValueStack* state_before = copy_state_exhandling();
2294   bool will_link;
2295   ciKlass* klass = stream()->get_klass(will_link);
2296   assert(klass->is_instance_klass(), "must be an instance klass");
2297   assert(!klass->is_valuetype(), "must not be a value klass");
2298   NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before, stream()->is_unresolved_klass());
2299   _memory->new_instance(new_instance);
2300   apush(append_split(new_instance));
2301 }
2302 
2303 void GraphBuilder::new_value_type_instance(int klass_index) {
2304   ValueStack* state_before = copy_state_exhandling();
2305   bool will_link;
2306   ciKlass* klass = stream()->get_klass(will_link);

2307   assert(klass->is_valuetype(), "must be a value klass");

2308   NewValueTypeInstance* new_instance = new NewValueTypeInstance(klass->as_value_klass(),
2309       state_before, stream()->is_unresolved_klass());
2310   _memory->new_instance(new_instance);
2311   apush(append_split(new_instance));




2312 }
2313 
2314 void GraphBuilder::new_type_array() {
2315   ValueStack* state_before = copy_state_exhandling();
2316   apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
2317 }
2318 
2319 
2320 void GraphBuilder::new_object_array() {
2321   bool will_link;
2322   ciKlass* klass = stream()->get_klass(will_link);
2323   bool never_null = stream()->is_klass_never_null();
2324   ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2325   NewArray* n = new NewObjectArray(klass, ipop(), state_before, never_null);
2326   apush(append_split(n));
2327 }
2328 
2329 
2330 bool GraphBuilder::direct_compare(ciKlass* k) {
2331   if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {




1839         assert(field->type()->is_valuetype(), "Sanity check");
1840         ciValueKlass* value_klass = field->type()->as_value_klass();
1841         int flattening_offset = field->offset() - value_klass->first_field_offset();
1842         copy_value_content(value_klass, val, value_klass->first_field_offset(), obj, field->offset(),
1843                    state_before, needs_patching);
1844       }
1845       break;
1846     }
1847     default:
1848       ShouldNotReachHere();
1849       break;
1850   }
1851 }
1852 
1853 // Baseline version of withfield, allocate every time
1854 void GraphBuilder::withfield(int field_index)
1855 {
1856   bool will_link;
1857   ciField* field_modify = stream()->get_field(will_link);
1858   ciInstanceKlass* holder = field_modify->holder();

1859   BasicType field_type = field_modify->type()->basic_type();
1860   ValueType* type = as_ValueType(field_type);
1861 
1862   // call will_link again to determine if the field is valid.
1863   const bool needs_patching = !holder->is_loaded() ||
1864                               !field_modify->will_link(method(), Bytecodes::_withfield) ||
1865                               PatchALot;
1866 
1867 
1868   scope()->set_wrote_final();
1869   scope()->set_wrote_fields();
1870 
1871   const int offset = !needs_patching ? field_modify->offset() : -1;
1872 
1873   if (!holder->is_loaded()) {
1874     ValueStack* state_before = copy_state_before();
1875     Value val = pop(type);
1876     Value obj = apop();
1877     apush(append_split(new WithField(obj->type(), state_before)));
1878     return;
1879   }
1880   ValueStack* state_before = copy_state_for_exception();
1881 
1882   Value val = pop(type);
1883   Value obj = apop();
1884 
1885   assert(holder->is_valuetype(), "must be a value klass");
1886   NewValueTypeInstance* new_instance = new NewValueTypeInstance(holder->as_value_klass(), state_before, false);
1887   _memory->new_instance(new_instance);
1888   apush(append_split(new_instance));
1889 
1890   for (int i = 0; i < holder->nof_nonstatic_fields(); i++) {
1891     ciField* field = holder->nonstatic_field_at(i);
1892     int off = field->offset();
1893 
1894     if (field->offset() != offset) {
1895       if (field->is_flattened()) {
1896         assert(field->type()->is_valuetype(), "Sanity check");
1897         assert(field->type()->is_valuetype(), "Only value types can be flattened");
1898         ciValueKlass* vk = field->type()->as_value_klass();
1899         copy_value_content(vk, obj, off, new_instance, vk->first_field_offset(), state_before, needs_patching);
1900       } else {
1901         // Only load those fields who are not modified
1902         LoadField* load = new LoadField(obj, off, field, false, state_before, needs_patching);
1903         Value replacement = append(load);
1904         StoreField* store = new StoreField(new_instance, off, field, replacement, false, state_before, needs_patching);
1905         append(store);


2292     }
2293   }
2294   if (profile_return() && result_type->is_object_kind()) {
2295     profile_return_type(result, target);
2296   }
2297 }
2298 
2299 
2300 void GraphBuilder::new_instance(int klass_index) {
2301   ValueStack* state_before = copy_state_exhandling();
2302   bool will_link;
2303   ciKlass* klass = stream()->get_klass(will_link);
2304   assert(klass->is_instance_klass(), "must be an instance klass");
2305   assert(!klass->is_valuetype(), "must not be a value klass");
2306   NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before, stream()->is_unresolved_klass());
2307   _memory->new_instance(new_instance);
2308   apush(append_split(new_instance));
2309 }
2310 
2311 void GraphBuilder::new_value_type_instance(int klass_index) {

2312   bool will_link;
2313   ciKlass* klass = stream()->get_klass(will_link);
2314   if (klass->is_loaded()) {
2315     assert(klass->is_valuetype(), "must be a value klass");
2316     ValueStack* state_before = copy_state_exhandling();
2317     NewValueTypeInstance* new_instance = new NewValueTypeInstance(klass->as_value_klass(),
2318         state_before, stream()->is_unresolved_klass());
2319     _memory->new_instance(new_instance);
2320     apush(append_split(new_instance));
2321   } else {
2322     ValueStack* state_before = copy_state_before();
2323     apush(append_split(new DefaultValue(objectType, state_before)));
2324   }
2325 }
2326 
2327 void GraphBuilder::new_type_array() {
2328   ValueStack* state_before = copy_state_exhandling();
2329   apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
2330 }
2331 
2332 
2333 void GraphBuilder::new_object_array() {
2334   bool will_link;
2335   ciKlass* klass = stream()->get_klass(will_link);
2336   bool never_null = stream()->is_klass_never_null();
2337   ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
2338   NewArray* n = new NewObjectArray(klass, ipop(), state_before, never_null);
2339   apush(append_split(n));
2340 }
2341 
2342 
2343 bool GraphBuilder::direct_compare(ciKlass* k) {
2344   if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {


< prev index next >