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