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 org.graalvm.compiler.hotspot.test; 26 27 import java.lang.invoke.ConstantCallSite; 28 import java.lang.invoke.MethodHandles; 29 import java.lang.invoke.MethodType; 30 31 import org.graalvm.compiler.nodes.IfNode; 32 import org.junit.Test; 33 34 import org.graalvm.compiler.api.directives.GraalDirectives; 35 import org.graalvm.compiler.api.replacements.MethodSubstitution; 36 import org.graalvm.compiler.replacements.test.MethodSubstitutionTest; 37 38 /** 39 * Tests HotSpot specific {@link MethodSubstitution}s. 40 */ 41 public class HotSpotMethodSubstitutionTest extends MethodSubstitutionTest { 42 43 @Test 44 public void testObjectSubstitutions() { 45 TestClassA obj = new TestClassA(); 46 47 testGraph("getClass0"); 48 testGraph("objectHashCode"); 49 50 test("getClass0", "a string"); 51 test("objectHashCode", obj); 52 53 testGraph("objectNotify", "Object.notify"); 54 testGraph("objectNotifyAll", "Object.notifyAll"); 55 56 synchronized (obj) { 116 return clazz.isArray(); 117 } 118 119 @SuppressWarnings("all") 120 public static boolean isPrimitive(Class<?> clazz) { 121 return clazz.isPrimitive(); 122 } 123 124 @SuppressWarnings("all") 125 public static Class<?> getSuperClass(Class<?> clazz) { 126 return clazz.getSuperclass(); 127 } 128 129 @SuppressWarnings("all") 130 public static Class<?> getComponentType(Class<?> clazz) { 131 return clazz.getComponentType(); 132 } 133 134 @Test 135 public void testThreadSubstitutions() { 136 testGraph("currentThread"); 137 assertInGraph(testGraph("threadIsInterrupted", "isInterrupted", true), IfNode.class); 138 assertInGraph(testGraph("threadInterrupted", "isInterrupted", true), IfNode.class); 139 140 Thread currentThread = Thread.currentThread(); 141 test("currentThread", currentThread); 142 test("threadIsInterrupted", currentThread); 143 } 144 145 @SuppressWarnings("all") 146 public static boolean currentThread(Thread other) { 147 return Thread.currentThread() == other; 148 } 149 150 @SuppressWarnings("all") 151 public static boolean threadIsInterrupted(Thread thread) { 152 return thread.isInterrupted(); 153 } 154 155 @SuppressWarnings("all") 156 public static boolean threadInterrupted() { 157 return Thread.interrupted(); 158 } 159 160 @Test 161 public void testSystemSubstitutions() { 162 testGraph("systemTime"); | 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 org.graalvm.compiler.hotspot.test; 26 27 import java.lang.invoke.ConstantCallSite; 28 import java.lang.invoke.MethodHandles; 29 import java.lang.invoke.MethodType; 30 31 import org.graalvm.compiler.api.directives.GraalDirectives; 32 import org.graalvm.compiler.api.replacements.MethodSubstitution; 33 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 34 import org.graalvm.compiler.hotspot.HotSpotBackend; 35 import org.graalvm.compiler.nodes.IfNode; 36 import org.graalvm.compiler.replacements.test.MethodSubstitutionTest; 37 import org.junit.Test; 38 39 /** 40 * Tests HotSpot specific {@link MethodSubstitution}s. 41 */ 42 public class HotSpotMethodSubstitutionTest extends MethodSubstitutionTest { 43 44 @Test 45 public void testObjectSubstitutions() { 46 TestClassA obj = new TestClassA(); 47 48 testGraph("getClass0"); 49 testGraph("objectHashCode"); 50 51 test("getClass0", "a string"); 52 test("objectHashCode", obj); 53 54 testGraph("objectNotify", "Object.notify"); 55 testGraph("objectNotifyAll", "Object.notifyAll"); 56 57 synchronized (obj) { 117 return clazz.isArray(); 118 } 119 120 @SuppressWarnings("all") 121 public static boolean isPrimitive(Class<?> clazz) { 122 return clazz.isPrimitive(); 123 } 124 125 @SuppressWarnings("all") 126 public static Class<?> getSuperClass(Class<?> clazz) { 127 return clazz.getSuperclass(); 128 } 129 130 @SuppressWarnings("all") 131 public static Class<?> getComponentType(Class<?> clazz) { 132 return clazz.getComponentType(); 133 } 134 135 @Test 136 public void testThreadSubstitutions() { 137 GraalHotSpotVMConfig config = ((HotSpotBackend) getBackend()).getRuntime().getVMConfig(); 138 testGraph("currentThread"); 139 if (config.osThreadInterruptedOffset != Integer.MAX_VALUE) { 140 assertInGraph(testGraph("threadIsInterrupted", "isInterrupted", true), IfNode.class); 141 assertInGraph(testGraph("threadInterrupted", "isInterrupted", true), IfNode.class); 142 } 143 144 Thread currentThread = Thread.currentThread(); 145 test("currentThread", currentThread); 146 if (config.osThreadInterruptedOffset != Integer.MAX_VALUE) { 147 test("threadIsInterrupted", currentThread); 148 } 149 } 150 151 @SuppressWarnings("all") 152 public static boolean currentThread(Thread other) { 153 return Thread.currentThread() == other; 154 } 155 156 @SuppressWarnings("all") 157 public static boolean threadIsInterrupted(Thread thread) { 158 return thread.isInterrupted(); 159 } 160 161 @SuppressWarnings("all") 162 public static boolean threadInterrupted() { 163 return Thread.interrupted(); 164 } 165 166 @Test 167 public void testSystemSubstitutions() { 168 testGraph("systemTime"); |