# HG changeset patch # User Doug Simon # Date 1422909608 -3600 # Node ID 0499dbe2da01f3fdacb9b0e005038e3b838d8684 # Parent 835819187e233b6f6cf676a743843180974a3396 factored out common code diff -r 835819187e23 -r 0499dbe2da01 graal/com.oracle.graal.java/src/com/oracle/graal/java/DefaultGraphBuilderPluginsProvider.java --- 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; } diff -r 835819187e23 -r 0499dbe2da01 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java --- 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; }