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 
  25 package jdk.vm.ci.hotspot.test;
  26 
  27 import static jdk.vm.ci.hotspot.test.TestHelper.ARRAYS_MAP;
  28 import static jdk.vm.ci.hotspot.test.TestHelper.ARRAY_ARRAYS_MAP;
  29 import static jdk.vm.ci.hotspot.test.TestHelper.CONSTANT_REFLECTION_PROVIDER;
  30 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_CONSTANT;
  31 import static jdk.vm.ci.hotspot.test.TestHelper.DUMMY_CLASS_INSTANCE;
  32 import static jdk.vm.ci.hotspot.test.TestHelper.STABLE_ARRAYS_MAP;
  33 import static jdk.vm.ci.hotspot.test.TestHelper.STABLE_ARRAY_ARRAYS_MAP;
  34 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_STABLE_FIELDS_MAP;
  35 import static jdk.vm.ci.hotspot.test.TestHelper.INSTANCE_FIELDS_MAP;
  36 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_FIELDS_MAP;
  37 import static jdk.vm.ci.hotspot.test.TestHelper.STATIC_STABLE_FIELDS_MAP;
  38 
  39 import java.util.LinkedList;
  40 import jdk.vm.ci.meta.JavaConstant;
  41 import org.testng.annotations.DataProvider;
  42 
  43 public class ReadStableFieldValueDataProvider {
  44 
  45     @DataProvider(name = "readStableFieldValueDataProvider")
  46     public static Object[][] readStableFieldValueDataProvider() {
  47         LinkedList<Object[]> cfgSet = new LinkedList<>();
  48         for (boolean isDefStab : new boolean[]{true, false}) {
  49             // Testing instance non-stable fields
  50             INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> {
  51                 cfgSet.add(new Object[]{instanceField.getKey(),
  52                         DUMMY_CLASS_CONSTANT,
  53                         isDefStab,
  54                         instanceField.getValue()});
  55             });
  56             // Testing static non-stable fields with null as receiver
  57             STATIC_FIELDS_MAP.entrySet().stream().forEach((staticField) -> {
  58                 cfgSet.add(new Object[]{staticField.getKey(),
  59                         null,
  60                         isDefStab,
  61                         staticField.getValue()});
  62             });
  63             // Testing static non-stable fields with JavaConstant.NULL_POINTER as receiver
  64             STATIC_FIELDS_MAP.entrySet().stream().forEach((staticField) -> {
  65                 cfgSet.add(new Object[]{staticField.getKey(),
  66                         JavaConstant.NULL_POINTER,
  67                         isDefStab,
  68                         staticField.getValue()});
  69             });
  70             // Testing instance stable fields
  71             INSTANCE_STABLE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> {
  72                 cfgSet.add(new Object[]{instanceField.getKey(),
  73                         DUMMY_CLASS_CONSTANT,
  74                         isDefStab,
  75                         instanceField.getValue()});
  76             });
  77             // Testing static stable fields with null as receiver
  78             STATIC_STABLE_FIELDS_MAP.entrySet().stream().forEach((staticField) -> {
  79                 cfgSet.add(new Object[]{staticField.getKey(),
  80                         null,
  81                         isDefStab,
  82                         staticField.getValue()});
  83             });
  84             // Testing static stable fields with JavaConstant.NULL_POINTER as receiver
  85             STATIC_STABLE_FIELDS_MAP.entrySet().stream().forEach((staticField) -> {
  86                 cfgSet.add(new Object[]{staticField.getKey(),
  87                         JavaConstant.NULL_POINTER,
  88                         isDefStab,
  89                         staticField.getValue()});
  90             });
  91             // Testing instance fields with JavaConstant.NULL_POINTER as receiver
  92             INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> {
  93                 cfgSet.add(new Object[]{instanceField.getKey(),
  94                         JavaConstant.NULL_POINTER,
  95                         isDefStab,
  96                         null});
  97             });
  98             // Testing instance fields with an object that does not have the field
  99             INSTANCE_FIELDS_MAP.entrySet().stream().forEach((instanceField) -> {
 100                 cfgSet.add(new Object[]{instanceField.getKey(),
 101                         CONSTANT_REFLECTION_PROVIDER.forObject(DUMMY_CLASS_INSTANCE.objectField),
 102                         isDefStab,
 103                         null});
 104             });
 105         }
 106         return cfgSet.toArray(new Object[0][0]);
 107     }
 108 
 109     @DataProvider(name = "readStableFieldValueArrayDataProvider")
 110     public static Object[][] readStableFieldValueArrayDataProvider() {
 111         LinkedList<Object[]> cfgSet = new LinkedList<>();
 112         for (boolean isDefStab : new boolean[]{true, false}) {
 113             // Testing instance non-stable array fields
 114             ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> {
 115                 cfgSet.add(new Object[]{instanceField.getKey(),
 116                         DUMMY_CLASS_CONSTANT,
 117                         isDefStab,
 118                         TestHelper.ARRAY_DIMENSION,
 119                         instanceField.getValue()});
 120             });
 121             // Testing instance stable array fields
 122             STABLE_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> {
 123                 cfgSet.add(new Object[]{instanceField.getKey(),
 124                         DUMMY_CLASS_CONSTANT,
 125                         isDefStab,
 126                         TestHelper.ARRAY_DIMENSION,
 127                         instanceField.getValue()});
 128             });
 129             // Testing instance non-stable array-of-array fields
 130             ARRAY_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> {
 131                 cfgSet.add(new Object[]{instanceField.getKey(),
 132                         DUMMY_CLASS_CONSTANT,
 133                         isDefStab,
 134                         TestHelper.ARRAY_OF_ARRAYS_DIMENSION,
 135                         instanceField.getValue()});
 136             });
 137             // Testing instance stable array-of-array fields
 138             STABLE_ARRAY_ARRAYS_MAP.entrySet().stream().forEach((instanceField) -> {
 139                 cfgSet.add(new Object[]{instanceField.getKey(),
 140                         DUMMY_CLASS_CONSTANT,
 141                         isDefStab,
 142                         TestHelper.ARRAY_OF_ARRAYS_DIMENSION,
 143                         instanceField.getValue()});
 144             });
 145         }
 146         return cfgSet.toArray(new Object[0][0]);
 147     }
 148 
 149     @DataProvider(name = "readStableFieldValueNegativeDataProvider")
 150     public static Object[][] readStableFieldValueNegativeDataProvider() {
 151         LinkedList<Object[]> cfgSet = new LinkedList<>();
 152         for (boolean isDefStab : new boolean[]{true, false}) {
 153             // Testing instance fields with null as receiver
 154             INSTANCE_FIELDS_MAP.keySet().stream().forEach((instanceField) -> {
 155                 cfgSet.add(new Object[]{instanceField, null, isDefStab});
 156             });
 157             // Testing null as a field argument
 158             cfgSet.add(new Object[]{null, null, isDefStab});
 159         }
 160         return cfgSet.toArray(new Object[0][0]);
 161     }
 162 }