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