001/* 002 * Copyright (c) 2009, 2014, 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.java; 024 025import jdk.internal.jvmci.meta.*; 026 027import com.oracle.graal.graphbuilderconf.*; 028import com.oracle.graal.nodes.*; 029import com.oracle.graal.nodes.spi.*; 030import com.oracle.graal.phases.*; 031import com.oracle.graal.phases.tiers.*; 032 033/** 034 * Parses the bytecodes of a method and builds the IR graph. 035 */ 036public class GraphBuilderPhase extends BasePhase<HighTierContext> { 037 038 private final GraphBuilderConfiguration graphBuilderConfig; 039 040 public GraphBuilderPhase(GraphBuilderConfiguration config) { 041 this.graphBuilderConfig = config; 042 } 043 044 @Override 045 protected void run(StructuredGraph graph, HighTierContext context) { 046 new Instance(context.getMetaAccess(), context.getStampProvider(), context.getConstantReflection(), graphBuilderConfig, context.getOptimisticOptimizations(), null).run(graph); 047 } 048 049 public GraphBuilderConfiguration getGraphBuilderConfig() { 050 return graphBuilderConfig; 051 } 052 053 // Fully qualified name is a workaround for JDK-8056066 054 public static class Instance extends com.oracle.graal.phases.Phase { 055 056 protected final MetaAccessProvider metaAccess; 057 protected final StampProvider stampProvider; 058 protected final ConstantReflectionProvider constantReflection; 059 protected final GraphBuilderConfiguration graphBuilderConfig; 060 protected final OptimisticOptimizations optimisticOpts; 061 private final IntrinsicContext initialIntrinsicContext; 062 063 public Instance(MetaAccessProvider metaAccess, StampProvider stampProvider, ConstantReflectionProvider constantReflection, GraphBuilderConfiguration graphBuilderConfig, 064 OptimisticOptimizations optimisticOpts, IntrinsicContext initialIntrinsicContext) { 065 this.graphBuilderConfig = graphBuilderConfig; 066 this.optimisticOpts = optimisticOpts; 067 this.metaAccess = metaAccess; 068 this.stampProvider = stampProvider; 069 this.constantReflection = constantReflection; 070 this.initialIntrinsicContext = initialIntrinsicContext; 071 } 072 073 @Override 074 protected void run(StructuredGraph graph) { 075 createBytecodeParser(graph, null, graph.method(), graph.getEntryBCI(), initialIntrinsicContext).buildRootMethod(); 076 } 077 078 /* Hook for subclasses of Instance to provide a subclass of BytecodeParser. */ 079 protected BytecodeParser createBytecodeParser(StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, int entryBCI, IntrinsicContext intrinsicContext) { 080 return new BytecodeParser(this, graph, parent, method, entryBCI, intrinsicContext); 081 } 082 } 083}