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