Skip to content

Commit 38bd251

Browse files
committed
Improve isMember* node.
1 parent 732f7ce commit 38bd251

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/GetPrototypeNode.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Set;
4444

4545
import com.oracle.truffle.api.dsl.Cached;
46+
import com.oracle.truffle.api.dsl.GenerateUncached;
4647
import com.oracle.truffle.api.dsl.Specialization;
4748
import com.oracle.truffle.api.frame.VirtualFrame;
4849
import com.oracle.truffle.api.instrumentation.Tag;
@@ -60,6 +61,7 @@
6061
import com.oracle.truffle.js.runtime.objects.Null;
6162
import com.oracle.truffle.js.runtime.util.JSClassProfile;
6263

64+
@GenerateUncached
6365
public abstract class GetPrototypeNode extends JavaScriptBaseNode {
6466
static final int MAX_SHAPE_COUNT = 2;
6567

@@ -101,26 +103,26 @@ static Property getPrototypeProperty(Shape shape) {
101103
}
102104

103105
@Specialization(guards = {"obj.getShape() == shape", "prototypeProperty != null"}, limit = "MAX_SHAPE_COUNT")
104-
public DynamicObject doCachedShape(DynamicObject obj,
106+
static DynamicObject doCachedShape(DynamicObject obj,
105107
@Cached("obj.getShape()") Shape shape,
106108
@Cached("getPrototypeProperty(shape)") Property prototypeProperty) {
107109
assert !JSGuards.isJSProxy(obj);
108110
return (DynamicObject) prototypeProperty.get(obj, shape);
109111
}
110112

111113
@Specialization(guards = "!isJSProxy(obj)", replaces = "doCachedShape")
112-
public DynamicObject doGeneric(DynamicObject obj) {
114+
static DynamicObject doGeneric(DynamicObject obj) {
113115
return JSObjectUtil.getPrototype(obj);
114116
}
115117

116118
@Specialization(guards = "isJSProxy(obj)")
117-
public DynamicObject doProxy(DynamicObject obj,
119+
static DynamicObject doProxy(DynamicObject obj,
118120
@Cached("create()") JSClassProfile jsclassProfile) {
119121
return JSObject.getPrototype(obj, jsclassProfile);
120122
}
121123

122124
@Specialization(guards = "!isDynamicObject(obj)")
123-
public DynamicObject doNotObject(@SuppressWarnings("unused") Object obj) {
125+
static DynamicObject doNotObject(@SuppressWarnings("unused") Object obj) {
124126
return Null.instance;
125127
}
126128
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/IsExtensibleNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.truffle.api.dsl.Cached;
4444
import com.oracle.truffle.api.dsl.Cached.Shared;
45+
import com.oracle.truffle.api.dsl.GenerateUncached;
4546
import com.oracle.truffle.api.dsl.ImportStatic;
4647
import com.oracle.truffle.api.dsl.Specialization;
4748
import com.oracle.truffle.api.object.DynamicObject;
@@ -55,6 +56,7 @@
5556
/**
5657
* Implements abstract operation IsExtensible.
5758
*/
59+
@GenerateUncached
5860
@ImportStatic({JSShape.class})
5961
public abstract class IsExtensibleNode extends JavaScriptBaseNode {
6062

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/interop/KeyInfoNode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
*/
4141
package com.oracle.truffle.js.nodes.interop;
4242

43+
import com.oracle.truffle.api.dsl.Cached;
4344
import com.oracle.truffle.api.dsl.GenerateUncached;
4445
import com.oracle.truffle.api.dsl.Specialization;
4546
import com.oracle.truffle.api.object.DynamicObject;
4647
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
47-
import com.oracle.truffle.js.runtime.JSRuntime;
48+
import com.oracle.truffle.js.nodes.access.GetPrototypeNode;
49+
import com.oracle.truffle.js.nodes.access.IsExtensibleNode;
50+
import com.oracle.truffle.js.nodes.unary.IsCallableNode;
4851
import com.oracle.truffle.js.runtime.builtins.JSProxy;
4952
import com.oracle.truffle.js.runtime.objects.JSObject;
5053
import com.oracle.truffle.js.runtime.objects.Null;
@@ -71,10 +74,13 @@ public abstract class KeyInfoNode extends JavaScriptBaseNode {
7174
public abstract boolean execute(DynamicObject receiver, String key, int query);
7275

7376
@Specialization
74-
static boolean member(DynamicObject target, String key, int query) {
77+
static boolean member(DynamicObject target, String key, int query,
78+
@Cached GetPrototypeNode getPrototype,
79+
@Cached IsCallableNode isCallable,
80+
@Cached IsExtensibleNode isExtensible) {
7581
PropertyDescriptor desc = null;
7682
boolean isProxy = false;
77-
for (DynamicObject proto = target; proto != Null.instance; proto = JSObject.getPrototype(proto)) {
83+
for (DynamicObject proto = target; proto != Null.instance; proto = getPrototype.executeJSObject(proto)) {
7884
desc = JSObject.getOwnProperty(proto, key);
7985
if (JSProxy.isJSProxy(proto)) {
8086
isProxy = true;
@@ -85,7 +91,7 @@ static boolean member(DynamicObject target, String key, int query) {
8591
}
8692
}
8793
if (desc == null) {
88-
if ((query & INSERTABLE) != 0 && JSObject.isExtensible(target)) {
94+
if ((query & INSERTABLE) != 0 && isExtensible.executeBoolean(target)) {
8995
return true;
9096
}
9197
return false;
@@ -109,7 +115,7 @@ static boolean member(DynamicObject target, String key, int query) {
109115
if ((query & WRITE_SIDE_EFFECTS) != 0 && writeSideEffects) {
110116
return true;
111117
}
112-
if ((query & INVOCABLE) != 0 && desc.isDataDescriptor() && JSRuntime.isCallable(desc.getValue())) {
118+
if ((query & INVOCABLE) != 0 && desc.isDataDescriptor() && isCallable.executeBoolean(desc.getValue())) {
113119
return true;
114120
}
115121
if ((query & REMOVABLE) != 0 && desc.getConfigurable()) {

0 commit comments

Comments
 (0)