src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/LIRIntrospection.java
changeset 58877 aec7bf35d6f5
parent 52910 583fd71c47d6
equal deleted inserted replaced
58876:1a8d65e71a66 58877:aec7bf35d6f5
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   212             }
   212             }
   213             return true;
   213             return true;
   214         }
   214         }
   215     }
   215     }
   216 
   216 
       
   217     private static boolean verifyAssignment(LIRInstruction inst, Value newValue, EnumSet<OperandFlag> flags) {
       
   218         Class<?> type = newValue.getClass();
       
   219         if (!flags.contains(REG)) {
       
   220             assert !type.isAssignableFrom(REGISTER_VALUE_CLASS) && !type.isAssignableFrom(VARIABLE_CLASS) : "Cannot assign RegisterValue / Variable to field without REG flag: " + inst + " newValue=" +
       
   221                             newValue;
       
   222         }
       
   223         if (!flags.contains(STACK)) {
       
   224             assert !type.isAssignableFrom(STACK_SLOT_CLASS) : "Cannot assign StackSlot to field without STACK flag: " + inst + " newValue=" +
       
   225                             newValue;
       
   226         }
       
   227         if (!flags.contains(CONST)) {
       
   228             assert !type.isAssignableFrom(CONSTANT_VALUE_CLASS) : "Cannot assign Constant to field without CONST flag: " + inst + " newValue=" +
       
   229                             newValue;
       
   230         }
       
   231         return true;
       
   232     }
       
   233 
   217     protected static void forEach(LIRInstruction inst, Values values, OperandMode mode, InstructionValueProcedure proc) {
   234     protected static void forEach(LIRInstruction inst, Values values, OperandMode mode, InstructionValueProcedure proc) {
   218         for (int i = 0; i < values.getCount(); i++) {
   235         for (int i = 0; i < values.getCount(); i++) {
   219             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i));
   236             assert LIRInstruction.ALLOWED_FLAGS.get(mode).containsAll(values.getFlags(i));
   220 
   237 
   221             if (i < values.getDirectCount()) {
   238             if (i < values.getDirectCount()) {
   226                     newValue = composite.forEachComponent(inst, mode, proc);
   243                     newValue = composite.forEachComponent(inst, mode, proc);
   227                 } else {
   244                 } else {
   228                     newValue = proc.doValue(inst, value, mode, values.getFlags(i));
   245                     newValue = proc.doValue(inst, value, mode, values.getFlags(i));
   229                 }
   246                 }
   230                 if (!value.identityEquals(newValue)) {
   247                 if (!value.identityEquals(newValue)) {
       
   248                     if (!(value instanceof CompositeValue)) {
       
   249                         assert verifyAssignment(inst, newValue, values.getFlags(i));
       
   250                     }
   231                     values.setValue(inst, i, newValue);
   251                     values.setValue(inst, i, newValue);
   232                 }
   252                 }
   233             } else {
   253             } else {
   234                 Value[] valueArray = values.getValueArray(inst, i);
   254                 Value[] valueArray = values.getValueArray(inst, i);
   235                 for (int j = 0; j < valueArray.length; j++) {
   255                 for (int j = 0; j < valueArray.length; j++) {