Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/call/InlinedBoxedDispatchNode.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
1 /* | |
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This | |
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, | |
4 * redistribute it and/or modify it under the terms of the: | |
5 * | |
6 * Eclipse Public License version 1.0 | |
7 * GNU General Public License version 2 | |
8 * GNU Lesser General Public License version 2.1 | |
9 */ | |
10 package com.oracle.truffle.ruby.nodes.call; | |
11 | |
12 import java.util.*; | |
13 | |
14 import com.oracle.truffle.api.*; | |
15 import com.oracle.truffle.api.frame.*; | |
16 import com.oracle.truffle.api.nodes.*; | |
17 import com.oracle.truffle.ruby.nodes.*; | |
18 import com.oracle.truffle.ruby.runtime.*; | |
19 import com.oracle.truffle.ruby.runtime.core.*; | |
20 import com.oracle.truffle.ruby.runtime.lookup.*; | |
21 import com.oracle.truffle.ruby.runtime.objects.*; | |
22 | |
23 /** | |
24 * A node in the dispatch chain that comes after the boxing point and caches a method on a full | |
25 * boxed {@link RubyBasicObject}, matching it by looking at the lookup node and assuming it has not | |
26 * been modified. | |
27 */ | |
28 public class InlinedBoxedDispatchNode extends BoxedDispatchNode { | |
29 | |
30 private final LookupNode expectedLookupNode; | |
31 private final Assumption unmodifiedAssumption; | |
32 | |
33 private final InlinableMethodImplementation method; | |
34 private final RubyRootNode rootNode; | |
35 | |
36 @Child protected BoxedDispatchNode next; | |
37 | |
38 public InlinedBoxedDispatchNode(RubyContext context, SourceSection sourceSection, LookupNode expectedLookupNode, InlinableMethodImplementation method, BoxedDispatchNode next) { | |
39 super(context, sourceSection); | |
40 | |
41 assert expectedLookupNode != null; | |
42 assert method != null; | |
43 | |
44 this.expectedLookupNode = expectedLookupNode; | |
45 unmodifiedAssumption = expectedLookupNode.getUnmodifiedAssumption(); | |
46 this.method = method; | |
47 this.rootNode = method.getCloneOfPristineRootNode(); | |
48 this.next = adoptChild(next); | |
49 } | |
50 | |
51 @Override | |
52 public Object dispatch(VirtualFrame frame, RubyBasicObject receiverObject, RubyProc blockObject, Object[] argumentsObjects) { | |
53 // Check the lookup node is what we expect | |
54 | |
55 if (receiverObject.getLookupNode() != expectedLookupNode) { | |
56 return next.dispatch(frame, receiverObject, blockObject, argumentsObjects); | |
57 } | |
58 | |
59 // Check the class has not been modified | |
60 | |
61 try { | |
62 unmodifiedAssumption.check(); | |
63 } catch (InvalidAssumptionException e) { | |
64 return respecialize("class modified", frame, receiverObject, blockObject, argumentsObjects); | |
65 } | |
66 | |
67 // Call the method | |
68 | |
69 Object[] modifiedArgumentsObjects; | |
70 | |
71 CompilerAsserts.compilationConstant(method.getShouldAppendCallNode()); | |
72 | |
73 if (method.getShouldAppendCallNode()) { | |
74 modifiedArgumentsObjects = Arrays.copyOf(argumentsObjects, argumentsObjects.length + 1); | |
75 modifiedArgumentsObjects[modifiedArgumentsObjects.length - 1] = this; | |
76 } else { | |
77 modifiedArgumentsObjects = argumentsObjects; | |
78 } | |
79 | |
80 final RubyArguments arguments = new RubyArguments(method.getDeclarationFrame(), receiverObject, blockObject, modifiedArgumentsObjects); | |
81 final VirtualFrame inlinedFrame = Truffle.getRuntime().createVirtualFrame(frame.pack(), arguments, method.getFrameDescriptor()); | |
82 return rootNode.execute(inlinedFrame); | |
83 } | |
84 } |