< prev index next >

src/share/vm/c1/c1_Canonicalizer.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2015, 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  *


 247 
 248   } else if ((lf = x->array()->as_LoadField()) != NULL) {
 249     ciField* field = lf->field();
 250     if (field->is_static_constant()) {
 251       assert(PatchALot || ScavengeRootsInCode < 2, "Constant field loads are folded during parsing");
 252       ciObject* c = field->constant_value().as_object();
 253       if (!c->is_null_object()) {
 254         set_constant(c->as_array()->length());
 255       }
 256     }
 257   }
 258 }
 259 
 260 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {
 261   StableArrayConstant* array = x->array()->type()->as_StableArrayConstant();
 262   IntConstant* index = x->index()->type()->as_IntConstant();
 263 
 264   assert(array == NULL || FoldStableValues, "not enabled");
 265 
 266   // Constant fold loads from stable arrays.
 267   if (array != NULL && index != NULL) {
 268     jint idx = index->value();
 269     if (idx < 0 || idx >= array->value()->length()) {
 270       // Leave the load as is. The range check will handle it.
 271       return;
 272     }
 273 
 274     ciConstant field_val = array->value()->element_value(idx);
 275     if (!field_val.is_null_or_zero()) {
 276       jint dimension = array->dimension();
 277       assert(dimension <= array->value()->array_type()->dimension(), "inconsistent info");
 278       ValueType* value = NULL;
 279       if (dimension > 1) {
 280         // Preserve information about the dimension for the element.
 281         assert(field_val.as_object()->is_array(), "not an array");
 282         value = new StableArrayConstant(field_val.as_object()->as_array(), dimension - 1);
 283       } else {
 284         assert(dimension == 1, "sanity");
 285         value = as_ValueType(field_val);
 286       }
 287       set_canonical(new Constant(value));


 293   // If a value is going to be stored into a field or array some of
 294   // the conversions emitted by javac are unneeded because the fields
 295   // are packed to their natural size.
 296   Convert* conv = x->value()->as_Convert();
 297   if (conv) {
 298     Value value = NULL;
 299     BasicType type = x->elt_type();
 300     switch (conv->op()) {
 301     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 302     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 303     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE) value = conv->value(); break;
 304     }
 305     // limit this optimization to current block
 306     if (value != NULL && in_current_block(conv)) {
 307       set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),
 308                                      x->elt_type(), value, x->state_before(),
 309                                      x->check_boolean()));
 310       return;
 311     }
 312   }
 313 
 314 
 315 }
 316 
 317 
 318 void Canonicalizer::do_NegateOp(NegateOp* x) {
 319   ValueType* t = x->x()->type();
 320   if (t->is_constant()) {
 321     switch (t->tag()) {
 322       case intTag   : set_constant(-t->as_IntConstant   ()->value()); return;
 323       case longTag  : set_constant(-t->as_LongConstant  ()->value()); return;
 324       case floatTag : set_constant(-t->as_FloatConstant ()->value()); return;
 325       case doubleTag: set_constant(-t->as_DoubleConstant()->value()); return;
 326       default       : ShouldNotReachHere();
 327     }
 328   }
 329 }
 330 
 331 
 332 void Canonicalizer::do_ArithmeticOp   (ArithmeticOp*    x) { do_Op2(x); }
 333 
 334 


   1 /*
   2  * Copyright (c) 1999, 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  *


 247 
 248   } else if ((lf = x->array()->as_LoadField()) != NULL) {
 249     ciField* field = lf->field();
 250     if (field->is_static_constant()) {
 251       assert(PatchALot || ScavengeRootsInCode < 2, "Constant field loads are folded during parsing");
 252       ciObject* c = field->constant_value().as_object();
 253       if (!c->is_null_object()) {
 254         set_constant(c->as_array()->length());
 255       }
 256     }
 257   }
 258 }
 259 
 260 void Canonicalizer::do_LoadIndexed    (LoadIndexed*     x) {
 261   StableArrayConstant* array = x->array()->type()->as_StableArrayConstant();
 262   IntConstant* index = x->index()->type()->as_IntConstant();
 263 
 264   assert(array == NULL || FoldStableValues, "not enabled");
 265 
 266   // Constant fold loads from stable arrays.
 267   if (!x->mismatched() && array != NULL && index != NULL) {
 268     jint idx = index->value();
 269     if (idx < 0 || idx >= array->value()->length()) {
 270       // Leave the load as is. The range check will handle it.
 271       return;
 272     }
 273 
 274     ciConstant field_val = array->value()->element_value(idx);
 275     if (!field_val.is_null_or_zero()) {
 276       jint dimension = array->dimension();
 277       assert(dimension <= array->value()->array_type()->dimension(), "inconsistent info");
 278       ValueType* value = NULL;
 279       if (dimension > 1) {
 280         // Preserve information about the dimension for the element.
 281         assert(field_val.as_object()->is_array(), "not an array");
 282         value = new StableArrayConstant(field_val.as_object()->as_array(), dimension - 1);
 283       } else {
 284         assert(dimension == 1, "sanity");
 285         value = as_ValueType(field_val);
 286       }
 287       set_canonical(new Constant(value));


 293   // If a value is going to be stored into a field or array some of
 294   // the conversions emitted by javac are unneeded because the fields
 295   // are packed to their natural size.
 296   Convert* conv = x->value()->as_Convert();
 297   if (conv) {
 298     Value value = NULL;
 299     BasicType type = x->elt_type();
 300     switch (conv->op()) {
 301     case Bytecodes::_i2b: if (type == T_BYTE)  value = conv->value(); break;
 302     case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
 303     case Bytecodes::_i2c: if (type == T_CHAR  || type == T_BYTE) value = conv->value(); break;
 304     }
 305     // limit this optimization to current block
 306     if (value != NULL && in_current_block(conv)) {
 307       set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),
 308                                      x->elt_type(), value, x->state_before(),
 309                                      x->check_boolean()));
 310       return;
 311     }
 312   }


 313 }
 314 
 315 
 316 void Canonicalizer::do_NegateOp(NegateOp* x) {
 317   ValueType* t = x->x()->type();
 318   if (t->is_constant()) {
 319     switch (t->tag()) {
 320       case intTag   : set_constant(-t->as_IntConstant   ()->value()); return;
 321       case longTag  : set_constant(-t->as_LongConstant  ()->value()); return;
 322       case floatTag : set_constant(-t->as_FloatConstant ()->value()); return;
 323       case doubleTag: set_constant(-t->as_DoubleConstant()->value()); return;
 324       default       : ShouldNotReachHere();
 325     }
 326   }
 327 }
 328 
 329 
 330 void Canonicalizer::do_ArithmeticOp   (ArithmeticOp*    x) { do_Op2(x); }
 331 
 332 


< prev index next >