1 /* 2 * Copyright (c) 2015, 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 compiler.jvmci.common.testcases; 25 26 import java.util.HashMap; 27 import java.util.Map; 28 29 public class MultipleImplementer2 implements MultipleImplementersInterface { 30 31 // Different access levels on the fields of this class are used on purpose. 32 // It is needed to verify jdk.vm.ci.CompilerToVM constant pool related 33 // methods, e.g. resolveFieldInPool. 34 35 private static int intStaticField = INT_CONSTANT; 36 final static long longStaticField = LONG_CONSTANT; 37 volatile static float floatStaticField = FLOAT_CONSTANT; 38 static double doubleStaticField = DOUBLE_CONSTANT; 39 public static String stringStaticField = STRING_CONSTANT; 40 protected static Object objectStaticField = OBJECT_CONSTANT; 41 42 public int intField = INT_CONSTANT; 43 private long longField = LONG_CONSTANT; 44 protected float floatField = FLOAT_CONSTANT; 45 transient double doubleField = DOUBLE_CONSTANT; 46 volatile String stringField = STRING_CONSTANT; 47 String stringFieldEmpty = ""; 48 final Object objectField; 49 50 public MultipleImplementer2() { 51 intField = Integer.MAX_VALUE; 52 longField = Long.MAX_VALUE; 53 floatField = Float.MAX_VALUE; 54 doubleField = Double.MAX_VALUE; 55 stringField = "Message"; 56 objectField = new Object(); 57 } 58 59 @Override 60 public void testMethod() { 61 // empty 62 } 63 64 @Override 65 public void finalize() throws Throwable { 66 super.finalize(); 67 } 68 69 public void lambdaUsingMethod2() { 70 Thread t = new Thread(this::testMethod); 71 t.start(); 72 } 73 74 /** 75 * This method is needed to have "getstatic" and "getfield" instructions 76 * in the class. These instructions are needed to test 77 * resolveFieldInPool method, because it needs a bytecode as one of its arguments. 78 */ 79 public void printFileds() { 80 System.out.println(intStaticField); 81 System.out.println(longStaticField); 82 System.out.println(floatStaticField); 83 System.out.println(doubleStaticField); 84 System.out.println(stringStaticField); 85 System.out.println(objectStaticField); 86 System.out.println(intField); 87 System.out.println(longField); 88 System.out.println(floatField); 89 System.out.println(doubleField); 90 System.out.println(stringField); 91 System.out.println(stringFieldEmpty); 92 System.out.println(objectField); 93 } 94 95 public static void staticMethod() { 96 System.getProperties(); // calling some static method 97 Map map = new HashMap(); // calling some constructor 98 map.put(OBJECT_CONSTANT, OBJECT_CONSTANT); // calling some interface method 99 map.remove(OBJECT_CONSTANT); // calling some default interface method 100 } 101 102 @Override 103 public void instanceMethod() { 104 toString(); // calling some virtual method 105 super.toString(); // calling some special method 106 } 107 108 @Override 109 public void anonClassMethod() { 110 new Runnable() { 111 @Override 112 public void run() { 113 System.out.println("Running"); 114 } 115 }.run(); 116 } 117 }