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