13514
|
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 com.oracle.truffle.api.*;
|
|
13 import com.oracle.truffle.api.frame.*;
|
|
14 import com.oracle.truffle.api.nodes.*;
|
|
15 import com.oracle.truffle.ruby.runtime.*;
|
|
16 import com.oracle.truffle.ruby.runtime.core.*;
|
|
17 import com.oracle.truffle.ruby.runtime.lookup.*;
|
|
18 import com.oracle.truffle.ruby.runtime.methods.*;
|
|
19 import com.oracle.truffle.ruby.runtime.objects.*;
|
|
20
|
|
21 /**
|
|
22 * A node in the dispatch chain that comes after the boxing point and caches a method on a full
|
|
23 * boxed Ruby BasicObject, matching it by looking at the lookup node and assuming it has not been
|
|
24 * modified.
|
|
25 */
|
|
26 public class CachedBoxedDispatchNode extends BoxedDispatchNode {
|
|
27
|
|
28 private final LookupNode expectedLookupNode;
|
|
29 private final Assumption unmodifiedAssumption;
|
|
30 private final RubyMethod method;
|
|
31
|
|
32 @Child protected BoxedDispatchNode next;
|
|
33
|
|
34 public CachedBoxedDispatchNode(RubyContext context, SourceSection sourceSection, LookupNode expectedLookupNode, RubyMethod method, BoxedDispatchNode next) {
|
|
35 super(context, sourceSection);
|
|
36
|
|
37 assert expectedLookupNode != null;
|
|
38 assert method != null;
|
|
39
|
|
40 this.expectedLookupNode = expectedLookupNode;
|
|
41 unmodifiedAssumption = expectedLookupNode.getUnmodifiedAssumption();
|
|
42 this.method = method;
|
|
43 this.next = adoptChild(next);
|
|
44 }
|
|
45
|
|
46 @Override
|
|
47 public Object dispatch(VirtualFrame frame, RubyBasicObject receiverObject, RubyProc blockObject, Object[] argumentsObjects) {
|
|
48 // Check the lookup node is what we expect
|
|
49
|
|
50 if (receiverObject.getLookupNode() != expectedLookupNode) {
|
|
51 return next.dispatch(frame, receiverObject, blockObject, argumentsObjects);
|
|
52 }
|
|
53
|
|
54 // Check the class has not been modified
|
|
55
|
|
56 try {
|
|
57 unmodifiedAssumption.check();
|
|
58 } catch (InvalidAssumptionException e) {
|
|
59 return respecialize("class modified", frame, receiverObject, blockObject, argumentsObjects);
|
|
60 }
|
|
61
|
|
62 // Call the method
|
|
63
|
|
64 return method.call(frame.pack(), receiverObject, blockObject, argumentsObjects);
|
|
65 }
|
|
66
|
|
67 }
|