-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Cache .singleton_class for other objects.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
1 parent
ba5ac0d
commit 1db32d2
Showing
1 changed file
with
48 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,12 @@ | |
*/ | ||
package org.jruby.truffle.language.objects; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | ||
import com.oracle.truffle.api.dsl.Cached; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.object.DynamicObject; | ||
import com.oracle.truffle.api.object.Shape; | ||
import com.oracle.truffle.api.profiles.BranchProfile; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.RubyContext; | ||
import org.jruby.truffle.core.Layouts; | ||
|
@@ -86,8 +85,8 @@ protected DynamicObject singletonClassSymbol(DynamicObject value) { | |
protected DynamicObject singletonClassClassCached( | ||
DynamicObject rubyClass, | ||
@Cached("rubyClass.getShape()") Shape cachedShape, | ||
@Cached("getSingletonClassForClass(rubyClass)") DynamicObject singletonClass) { | ||
return singletonClass; | ||
@Cached("getSingletonClassForClass(rubyClass)") DynamicObject cachedSingletonClass) { | ||
return cachedSingletonClass; | ||
} | ||
|
||
@Specialization( | ||
|
@@ -98,19 +97,48 @@ protected DynamicObject singletonClassClassUncached(DynamicObject rubyClass) { | |
return getSingletonClassForClass(rubyClass); | ||
} | ||
|
||
@Specialization(guards = { | ||
"!isNil(object)", | ||
"!isRubyBignum(object)", | ||
"!isRubySymbol(object)", | ||
"!isRubyClass(object)" | ||
}) | ||
protected DynamicObject singletonClass( | ||
@Specialization( | ||
guards = { | ||
"!isNil(object)", | ||
"!isRubyBignum(object)", | ||
"!isRubySymbol(object)", | ||
"!isRubyClass(object)", | ||
"object == cachedObject", | ||
"object.getShape() == cachedShape" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eregon
Member
|
||
}, | ||
limit = "getCacheLimit()") | ||
protected DynamicObject singletonClassInstanceCached( | ||
DynamicObject object, | ||
@Cached("create()") BranchProfile needsToFreeze) { | ||
if (RubyGuards.isRubyClass(object)) { | ||
return ClassNodes.getSingletonClass(getContext(), object); | ||
} | ||
@Cached("object") DynamicObject cachedObject, | ||
@Cached("object.getShape()") Shape cachedShape, | ||
@Cached("getSingletonClassForInstance(object)") DynamicObject cachedSingletonClass) { | ||
return cachedSingletonClass; | ||
} | ||
|
||
@Specialization( | ||
guards = { | ||
"!isNil(object)", | ||
"!isRubyBignum(object)", | ||
"!isRubySymbol(object)", | ||
"!isRubyClass(object)" | ||
}, | ||
contains = "singletonClassInstanceCached" | ||
) | ||
protected DynamicObject singletonClassInstanceUncached(DynamicObject object) { | ||
return getSingletonClassForInstance(object); | ||
} | ||
|
||
private DynamicObject noSingletonClass() { | ||
throw new RaiseException(coreLibrary().typeErrorCantDefineSingleton(this)); | ||
} | ||
|
||
@TruffleBoundary | ||
protected DynamicObject getSingletonClassForClass(DynamicObject rubyClass) { | ||
return ClassNodes.getSingletonClass(getContext(), rubyClass); | ||
} | ||
|
||
@TruffleBoundary | ||
protected DynamicObject getSingletonClassForInstance(DynamicObject object) { | ||
if (Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(object))) { | ||
return Layouts.BASIC_OBJECT.getMetaClass(object); | ||
} | ||
|
@@ -123,19 +151,18 @@ protected DynamicObject singletonClass( | |
attached = object; | ||
} | ||
|
||
final String name = String.format("#<Class:#<%s:0x%x>>", Layouts.MODULE.getFields(logicalClass).getName(), ObjectIDOperations.verySlowGetObjectID(getContext(), object)); | ||
final DynamicObject singletonClass = ClassNodes.createSingletonClassOfObject(getContext(), logicalClass, attached, name); | ||
final String name = String.format("#<Class:#<%s:0x%x>>", Layouts.MODULE.getFields(logicalClass).getName(), | ||
ObjectIDOperations.verySlowGetObjectID(getContext(), object)); | ||
|
||
final DynamicObject singletonClass = ClassNodes.createSingletonClassOfObject( | ||
getContext(), logicalClass, attached, name); | ||
|
||
if (isFrozenNode == null) { | ||
CompilerDirectives.transferToInterpreter(); | ||
isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null)); | ||
} | ||
|
||
if (isFrozenNode.executeIsFrozen(object)) { | ||
needsToFreeze.enter(); | ||
|
||
if (freezeNode == null) { | ||
CompilerDirectives.transferToInterpreter(); | ||
freezeNode = insert(FreezeNodeGen.create(getContext(), getSourceSection(), null)); | ||
} | ||
|
||
|
@@ -147,14 +174,6 @@ protected DynamicObject singletonClass( | |
return singletonClass; | ||
} | ||
|
||
private DynamicObject noSingletonClass() { | ||
throw new RaiseException(coreLibrary().typeErrorCantDefineSingleton(this)); | ||
} | ||
|
||
protected DynamicObject getSingletonClassForClass(DynamicObject rubyClass) { | ||
return ClassNodes.getSingletonClass(getContext(), rubyClass); | ||
} | ||
|
||
protected int getCacheLimit() { | ||
return getContext().getOptions().CLASS_CACHE; | ||
} | ||
|
We should have guards on Shapes like
isRubySymbol(Shape)
or as in ShapeCachingGuards.Then, a Shape check is enough and all other guards can be on the slow path.