001/* 002 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.hotspot; 024 025import com.oracle.graal.compiler.common.spi.*; 026import com.oracle.graal.debug.*; 027import com.oracle.graal.debug.Debug.*; 028 029import jdk.internal.jvmci.hotspot.*; 030import jdk.internal.jvmci.meta.*; 031import jdk.internal.jvmci.service.*; 032import static com.oracle.graal.compiler.common.GraalOptions.*; 033import static jdk.internal.jvmci.hotspot.InitTimer.*; 034 035import com.oracle.graal.hotspot.meta.*; 036import com.oracle.graal.hotspot.stubs.*; 037import com.oracle.graal.nodes.spi.*; 038 039/** 040 * Common functionality of HotSpot host backends. 041 */ 042public abstract class HotSpotHostBackend extends HotSpotBackend { 043 044 /** 045 * Descriptor for {@code SharedRuntime::deopt_blob()->unpack()} or 046 * {@link DeoptimizationStub#deoptimizationHandler} depending on 047 * {@link HotSpotBackend.Options#PreferGraalStubs}. 048 */ 049 public static final ForeignCallDescriptor DEOPTIMIZATION_HANDLER = new ForeignCallDescriptor("deoptHandler", void.class); 050 051 /** 052 * Descriptor for {@code SharedRuntime::deopt_blob()->uncommon_trap()} or 053 * {@link UncommonTrapStub#uncommonTrapHandler} depending on 054 * {@link HotSpotBackend.Options#PreferGraalStubs}. 055 */ 056 public static final ForeignCallDescriptor UNCOMMON_TRAP_HANDLER = new ForeignCallDescriptor("uncommonTrapHandler", void.class); 057 058 /** 059 * This will be 0 if stack banging is disabled. 060 */ 061 protected final int pagesToBang; 062 063 public HotSpotHostBackend(HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) { 064 super(runtime, providers); 065 this.pagesToBang = runtime.getConfig().useStackBanging ? runtime.getConfig().stackShadowPages : 0; 066 } 067 068 @Override 069 public void completeInitialization() { 070 final HotSpotProviders providers = getProviders(); 071 HotSpotVMConfig config = getRuntime().getConfig(); 072 HotSpotHostForeignCallsProvider foreignCalls = (HotSpotHostForeignCallsProvider) providers.getForeignCalls(); 073 final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer(); 074 HotSpotReplacementsImpl replacements = (HotSpotReplacementsImpl) providers.getReplacements(); 075 076 try (InitTimer st = timer("foreignCalls.initialize")) { 077 foreignCalls.initialize(providers, config); 078 } 079 try (InitTimer st = timer("lowerer.initialize")) { 080 lowerer.initialize(providers, config); 081 } 082 083 // Install intrinsics. 084 if (Intrinsify.getValue()) { 085 try (Scope s = Debug.scope("RegisterReplacements", new DebugDumpScope("RegisterReplacements"))) { 086 try (InitTimer st = timer("replacementsProviders.registerReplacements")) { 087 Iterable<ReplacementsProvider> sl = Services.load(ReplacementsProvider.class); 088 for (ReplacementsProvider replacementsProvider : sl) { 089 replacementsProvider.registerReplacements(providers.getMetaAccess(), lowerer, providers.getSnippetReflection(), replacements, providers.getCodeCache().getTarget()); 090 } 091 } 092 if (BootstrapReplacements.getValue()) { 093 for (ResolvedJavaMethod method : replacements.getAllReplacements()) { 094 replacements.getSubstitution(method, -1); 095 } 096 } 097 } catch (Throwable e) { 098 throw Debug.handle(e); 099 } 100 } 101 } 102}