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