1 /*
   2  * Copyright (c) 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  */
  23 
  24 package jdk.vm.ci.hotspot.test;
  25 
  26 import static jdk.vm.ci.hotspot.test.TestHelper.CONSTANT_REFLECTION_PROVIDER;
  27 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_INSTANCE;
  28 
  29 import java.util.HashMap;
  30 import java.util.LinkedList;
  31 import java.util.Objects;
  32 import jdk.vm.ci.meta.Constant;
  33 import jdk.vm.ci.meta.JavaConstant;
  34 import org.testng.annotations.DataProvider;
  35 
  36 public class ConstantEqualsDataProvider {
  37     @DataProvider(name = "constantEqualsDataProvider")
  38     public static Object[][] constantEqualsDataProvider() {
  39         HashMap<Object, Constant> constMap = new HashMap<>();
  40         constMap.put(DUMMY_CLASS_INSTANCE.booleanField, JavaConstant.forBoolean(DUMMY_CLASS_INSTANCE.booleanField));
  41         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultBooleanField,
  42                 JavaConstant.forBoolean(DUMMY_CLASS_INSTANCE.stableDefaultBooleanField));
  43         constMap.put(DUMMY_CLASS_INSTANCE.byteField, JavaConstant.forByte(DUMMY_CLASS_INSTANCE.byteField));
  44         constMap.put(DUMMY_CLASS_INSTANCE.finalByteField, JavaConstant.forByte(DUMMY_CLASS_INSTANCE.finalByteField));
  45         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultByteField,
  46                 JavaConstant.forByte(DUMMY_CLASS_INSTANCE.stableDefaultByteField));
  47         constMap.put(DUMMY_CLASS_INSTANCE.shortField, JavaConstant.forShort(DUMMY_CLASS_INSTANCE.shortField));
  48         constMap.put(DUMMY_CLASS_INSTANCE.finalShortField, JavaConstant.forShort(DUMMY_CLASS_INSTANCE.finalShortField));
  49         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultShortField,
  50                 JavaConstant.forShort(DUMMY_CLASS_INSTANCE.stableDefaultShortField));
  51         constMap.put(DUMMY_CLASS_INSTANCE.intField, JavaConstant.forInt(DUMMY_CLASS_INSTANCE.intField));
  52         constMap.put(DUMMY_CLASS_INSTANCE.finalIntField, JavaConstant.forInt(DUMMY_CLASS_INSTANCE.finalIntField));
  53         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultIntField,
  54                 JavaConstant.forInt(DUMMY_CLASS_INSTANCE.stableDefaultIntField));
  55         constMap.put(DUMMY_CLASS_INSTANCE.longField, JavaConstant.forLong(DUMMY_CLASS_INSTANCE.longField));
  56         constMap.put(DUMMY_CLASS_INSTANCE.finalLongField, JavaConstant.forLong(DUMMY_CLASS_INSTANCE.finalLongField));
  57         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultLongField,
  58                 JavaConstant.forLong(DUMMY_CLASS_INSTANCE.stableDefaultLongField));
  59         constMap.put(DUMMY_CLASS_INSTANCE.doubleField, JavaConstant.forDouble(DUMMY_CLASS_INSTANCE.doubleField));
  60         constMap.put(DUMMY_CLASS_INSTANCE.finalDoubleField,
  61                 JavaConstant.forDouble(DUMMY_CLASS_INSTANCE.finalDoubleField));
  62         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultDoubleField,
  63                 JavaConstant.forDouble(DUMMY_CLASS_INSTANCE.stableDefaultDoubleField));
  64         constMap.put(DUMMY_CLASS_INSTANCE.floatField, JavaConstant.forFloat(DUMMY_CLASS_INSTANCE.floatField));
  65         constMap.put(DUMMY_CLASS_INSTANCE.finalFloatField, JavaConstant.forFloat(DUMMY_CLASS_INSTANCE.finalFloatField));
  66         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultFloatField,
  67                 JavaConstant.forFloat(DUMMY_CLASS_INSTANCE.stableDefaultFloatField));
  68         constMap.put(DUMMY_CLASS_INSTANCE.charField, JavaConstant.forChar(DUMMY_CLASS_INSTANCE.charField));
  69         constMap.put(DUMMY_CLASS_INSTANCE.finalCharField, JavaConstant.forChar(DUMMY_CLASS_INSTANCE.finalCharField));
  70         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultCharField,
  71                 JavaConstant.forChar(DUMMY_CLASS_INSTANCE.stableDefaultCharField));
  72         constMap.put(DUMMY_CLASS_INSTANCE.stringField,
  73                 CONSTANT_REFLECTION_PROVIDER.forString(DUMMY_CLASS_INSTANCE.stringField));
  74         constMap.put(DUMMY_CLASS_INSTANCE.stringField2,
  75                 CONSTANT_REFLECTION_PROVIDER.forString(DUMMY_CLASS_INSTANCE.stringField2));
  76         constMap.put(DUMMY_CLASS_INSTANCE.objectField,
  77                 CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.objectField));
  78         constMap.put(DUMMY_CLASS_INSTANCE.finalObjectField,
  79                 CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.finalObjectField));
  80         constMap.put(DUMMY_CLASS_INSTANCE.stableDefaultObjectField,
  81                 CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.stableDefaultObjectField));
  82         constMap.put(null, null);
  83         constMap.put(JavaConstant.NULL_POINTER, JavaConstant.NULL_POINTER);
  84         LinkedList<Object[]> cfgSet = new LinkedList<>();
  85         constMap.entrySet().stream().forEach((obj1) -> {
  86             constMap.entrySet().stream().forEach((obj2) -> {
  87                 cfgSet.add(new Object[]{obj1.getValue(), obj2.getValue(),
  88                         Objects.equals(obj1.getKey(), obj2.getKey())});
  89             });
  90         });
  91         return cfgSet.toArray(new Object[0][0]);
  92     }
  93 }