Mercurial > hg > graal-compiler
view graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalRuntimeAccess.java @ 5220:a9e4b30968d4
Estimate size of loop and peel only if resulting graph is not too big
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 10 Apr 2012 14:05:14 +0200 |
parents | e808627bd16f |
children |
line wrap: on
line source
/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.oracle.graal.compiler.tests; import java.lang.reflect.*; import java.util.*; import com.oracle.graal.cri.*; /** * Utility for getting a {@link GraalRuntime} instance from the current execution environment. */ class GraalRuntimeAccess { /** * The known classes declaring a {@code getGraalRuntime()} method. These class names * have aliases that can be used with the {@code "graal.runtime"} system property to * specify the VM environment to try first when getting a Graal runtime instance. */ private static Map<String, String> graalRuntimeFactoryClasses = new LinkedHashMap<>(); static { graalRuntimeFactoryClasses.put("HotSpot", "com.oracle.graal.hotspot.CompilerImpl"); graalRuntimeFactoryClasses.put("Maxine", "com.oracle.max.vm.ext.maxri.MaxRuntime"); } /** * Gets a Graal runtime instance from the current execution environment. */ static GraalRuntime getGraalRuntime() { String vm = System.getProperty("graal.runtime"); if (vm != null) { String cn = graalRuntimeFactoryClasses.get(vm); if (cn != null) { GraalRuntime graal = getGraalRuntime(cn); if (graal != null) { return graal; } } } for (String className : graalRuntimeFactoryClasses.values()) { GraalRuntime graal = getGraalRuntime(className); if (graal != null) { return graal; } } throw new InternalError("Could not create a GraalRuntime instance"); } /** * Calls {@code getGraalRuntime()} via reflection on a given class. * * @return {@code null} if there was an error invoking the methodor if the method return {@code null} itself */ private static GraalRuntime getGraalRuntime(String className) { try { Class<?> c = Class.forName(className); Method m = c.getDeclaredMethod("getGraalRuntime"); return (GraalRuntime) m.invoke(null); } catch (Exception e) { //e.printStackTrace(); System.err.println(e); return null; } } }