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.DUMMY_CLASS_CONSTANT;
  27 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_STABLE_FIELDS_MAP;
  28 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_FINAL_DEFAULT_FIELDS_MAP;
  29 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_FINAL_FIELDS_MAP;
  30 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_FIELDS_MAP;
  31 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_STABLE_DEFAULT_FIELDS_MAP;
  32 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_FIELDS_MAP;
  33 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_FINAL_FIELDS_MAP;
  34 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_STABLE_FIELDS_MAP;
  35 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_STABLE_DEFAULT_FIELDS_MAP;
  36 
  37 import java.util.LinkedList;
  38 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  39 import jdk.vm.ci.meta.JavaConstant;
  40 import org.testng.annotations.DataProvider;
  41 
  42 
  43 public class ReadConstantFieldValueDataProvider {
  44 
  45     @DataProvider(name = "readConstantFieldValueDataProvider")
  46     public static Object[][] readConstantFieldValueDataProvider() {
  47         LinkedList<Object[]> cfgSet = new LinkedList<>();
  48         // Testing static final fields
  49         STATIC_FINAL_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  50             cfgSet.add(new Object[]{field.getKey(), null, field.getValue(), "static final field"});
  51         });
  52         // Testing static stable fields
  53         STATIC_STABLE_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  54             cfgSet.add(new Object[]{field.getKey(), null, field.getValue(), "static stable field"});
  55         });
  56         // Testing instance final non-default fields
  57         INSTANCE_FINAL_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  58             cfgSet.add(new Object[]{field.getKey(),
  59                     DUMMY_CLASS_CONSTANT,
  60                     field.getValue(),
  61                     "instance final field"});
  62         });
  63         // Testing instance final default fields.
  64         boolean trustDefFinal = HotSpotJVMCIRuntime.Option.TrustFinalDefaultFields.getBoolean();
  65         INSTANCE_FINAL_DEFAULT_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  66             JavaConstant expected = trustDefFinal ? field.getValue() : null;
  67             cfgSet.add(new Object[]{field.getKey(),
  68                     DUMMY_CLASS_CONSTANT,
  69                     expected,
  70                     "instance final default field"});
  71         });
  72         // Testing instance stable non-default fields
  73         INSTANCE_STABLE_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  74             cfgSet.add(new Object[]{field.getKey(),
  75                     DUMMY_CLASS_CONSTANT,
  76                     field.getValue(),
  77                     "instance stable field"});
  78         });
  79         // Testing instance stable default fields
  80         INSTANCE_STABLE_DEFAULT_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  81             cfgSet.add(new Object[]{field.getKey(),
  82                     DUMMY_CLASS_CONSTANT,
  83                     null,
  84                     "instance stable default field"});
  85         });
  86         // Testing regular instance fields
  87         INSTANCE_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  88             cfgSet.add(new Object[]{field.getKey(), DUMMY_CLASS_CONSTANT, null, "instance field"});
  89         });
  90         // Testing regular static fields
  91         STATIC_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  92             cfgSet.add(new Object[]{field.getKey(), null, null, "static field"});
  93         });
  94         // Testing static stable fields
  95         STATIC_STABLE_DEFAULT_FIELDS_MAP.entrySet().stream().forEach((field) -> {
  96             cfgSet.add(new Object[]{field.getKey(), null, null, "static stable default field"});
  97         });
  98         return cfgSet.toArray(new Object[0][0]);
  99     }
 100 
 101     @DataProvider(name = "readConstantFieldValueNegativeDataProvider")
 102     public static Object[][] readConstantFieldValueNegativeDataProvider() {
 103         LinkedList<Object[]> cfgSet = new LinkedList<>();
 104         // Testing instance fields with null as receiver
 105         INSTANCE_FIELDS_MAP.entrySet().stream().forEach((field) -> {
 106             cfgSet.add(new Object[]{field.getKey(), null});
 107         });
 108         // Testing null as a field argument
 109         cfgSet.add(new Object[]{null, null});
 110         return cfgSet.toArray(new Object[0][0]);
 111     }
 112 }