Mercurial > hg > truffle
changeset 19069:0499dbe2da01
factored out common code
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 02 Feb 2015 21:40:08 +0100 |
parents | 835819187e23 |
children | 69f2926cd2ab |
files | graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultGraphBuilderPluginsProvider.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java |
diffstat | 2 files changed, 23 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultGraphBuilderPluginsProvider.java Mon Feb 02 21:38:47 2015 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultGraphBuilderPluginsProvider.java Mon Feb 02 21:40:08 2015 +0100 @@ -22,10 +22,8 @@ */ package com.oracle.graal.java; -import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; -import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; @@ -44,25 +42,9 @@ enum ObjectPlugin implements GraphBuilderPlugin { init() { public boolean handleInvocation(GraphBuilderContext builder, ValueNode[] args) { - assert args.length == 1; - ValueNode rcvr = args[0]; - ObjectStamp objectStamp = (ObjectStamp) rcvr.stamp(); - - boolean needsCheck = true; - if (objectStamp.isExactType()) { - needsCheck = objectStamp.type().hasFinalizer(); - } else if (objectStamp.type() != null && !objectStamp.type().hasFinalizableSubclass()) { - // if either the declared type of receiver or the holder - // can be assumed to have no finalizers - Assumptions assumptions = builder.getAssumptions(); - if (assumptions.useOptimisticAssumptions()) { - assumptions.recordNoFinalizableSubclassAssumption(objectStamp.type()); - needsCheck = false; - } - } - - if (needsCheck) { - builder.append(new RegisterFinalizerNode(rcvr)); + ValueNode object = args[0]; + if (RegisterFinalizerNode.mayHaveFinalizer(object, builder.getAssumptions())) { + builder.append(new RegisterFinalizerNode(object)); } return true; }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java Mon Feb 02 21:38:47 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java Mon Feb 02 21:40:08 2015 +0100 @@ -56,27 +56,31 @@ gen.getLIRGeneratorTool().emitForeignCall(linkage, gen.state(this), gen.operand(getValue())); } + /** + * Determines if the compiler should emit code to test whether a given object has a finalizer + * that must be registered with the runtime upon object initialization. + */ + public static boolean mayHaveFinalizer(ValueNode object, Assumptions assumptions) { + ObjectStamp objectStamp = (ObjectStamp) object.stamp(); + if (objectStamp.isExactType()) { + return objectStamp.type().hasFinalizer(); + } else if (objectStamp.type() != null && !objectStamp.type().hasFinalizableSubclass()) { + // if either the declared type of receiver or the holder + // can be assumed to have no finalizers + if (assumptions.useOptimisticAssumptions()) { + assumptions.recordNoFinalizableSubclassAssumption(objectStamp.type()); + return false; + } + } + return true; + } + @Override public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { if (!(forValue.stamp() instanceof ObjectStamp)) { return this; } - - ObjectStamp objectStamp = (ObjectStamp) forValue.stamp(); - - boolean needsCheck = true; - if (objectStamp.isExactType()) { - needsCheck = objectStamp.type().hasFinalizer(); - } else if (objectStamp.type() != null && !objectStamp.type().hasFinalizableSubclass()) { - // if either the declared type of receiver or the holder - // can be assumed to have no finalizers - if (tool.assumptions().useOptimisticAssumptions()) { - tool.assumptions().recordNoFinalizableSubclassAssumption(objectStamp.type()); - needsCheck = false; - } - } - - if (!needsCheck) { + if (!mayHaveFinalizer(forValue, tool.assumptions())) { return null; }