changeset 18161:94f16a759646

Truffle: remove FrameTypeConversion interface
author Andreas Woess <andreas.woess@jku.at>
date Thu, 23 Oct 2014 13:45:59 +0200
parents 30e03a7f9110
children ab62800259ff
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/frame/NewFrameNode.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameTypeConversion.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultFrameTypeConversion.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java
diffstat 8 files changed, 34 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/FrameWithoutBoxing.java	Thu Oct 23 13:45:59 2014 +0200
@@ -51,7 +51,7 @@
         this.arguments = arguments;
         int size = descriptor.getSize();
         this.locals = new Object[size];
-        Arrays.fill(locals, descriptor.getTypeConversion().getDefaultValue());
+        Arrays.fill(locals, descriptor.getDefaultValue());
         this.primitiveLocals = new long[size];
         this.tags = new byte[size];
     }
@@ -252,12 +252,6 @@
         byte tag = this.getTags()[slotIndex];
         if (tag != accessKind.ordinal()) {
             CompilerDirectives.transferToInterpreter();
-            if (slot.getKind() == accessKind || tag == 0) {
-                descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot));
-                if (getTags()[slotIndex] == accessKind.ordinal()) {
-                    return;
-                }
-            }
             throw new FrameSlotTypeException();
         }
     }
@@ -293,7 +287,7 @@
         int newSize = descriptor.getSize();
         if (newSize > oldSize) {
             locals = Arrays.copyOf(locals, newSize);
-            Arrays.fill(locals, oldSize, newSize, descriptor.getTypeConversion().getDefaultValue());
+            Arrays.fill(locals, oldSize, newSize, descriptor.getDefaultValue());
             primitiveLocals = Arrays.copyOf(primitiveLocals, newSize);
             tags = Arrays.copyOf(tags, newSize);
             return true;
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/frame/NewFrameNode.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/frame/NewFrameNode.java	Thu Oct 23 13:45:59 2014 +0200
@@ -177,7 +177,7 @@
 
         if (frameSize > 0) {
             FrameDescriptor frameDescriptor = getConstantFrameDescriptor();
-            ConstantNode objectDefault = ConstantNode.forConstant(getSnippetReflection().forObject(frameDescriptor.getTypeConversion().getDefaultValue()), tool.getMetaAccessProvider(), graph());
+            ConstantNode objectDefault = ConstantNode.forConstant(getSnippetReflection().forObject(frameDescriptor.getDefaultValue()), tool.getMetaAccessProvider(), graph());
             ConstantNode tagDefault = ConstantNode.forByte((byte) 0, graph());
             Arrays.fill(objectArrayEntryState, objectDefault);
             Arrays.fill(tagArrayEntryState, tagDefault);
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java	Thu Oct 23 13:45:59 2014 +0200
@@ -117,6 +117,7 @@
             if (o instanceof Integer) {
                 frame.setInt(slot, (Integer) o);
             } else {
+                slot.setKind(FrameSlotKind.Object);
                 frame.setObject(slot, o);
                 this.replace(new ObjectAssignLocal(slot, value));
             }
@@ -136,6 +137,7 @@
         @Override
         Object execute(VirtualFrame frame) {
             Object o = value.execute(frame);
+            slot.setKind(FrameSlotKind.Object);
             frame.setObject(slot, o);
             return null;
         }
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java	Thu Oct 23 13:45:59 2014 +0200
@@ -30,7 +30,7 @@
 
 /**
  * <h3>Specializing Return Types</h3>
- * 
+ *
  * <p>
  * In order to avoid boxing and/or type casts on the return value of a node, the return value the
  * method for executing a node can have a specific type and need not be of type
@@ -124,6 +124,7 @@
                 int result = value.executeInt(frame);
                 frame.setInt(slot, result);
             } catch (UnexpectedResultException e) {
+                slot.setKind(FrameSlotKind.Object);
                 frame.setObject(slot, e.getResult());
                 replace(new ObjectAssignLocal(slot, value));
             }
@@ -143,6 +144,7 @@
         @Override
         Object execute(VirtualFrame frame) {
             Object o = value.execute(frame);
+            slot.setKind(FrameSlotKind.Object);
             frame.setObject(slot, o);
             return null;
         }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Thu Oct 23 13:45:59 2014 +0200
@@ -27,7 +27,6 @@
 import java.util.*;
 
 import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.impl.*;
 
 /**
  * Descriptor of the slots of frame objects. Multiple frame instances are associated with one such
@@ -35,23 +34,31 @@
  */
 public final class FrameDescriptor implements Cloneable {
 
-    private final FrameTypeConversion typeConversion;
+    private final Object defaultValue;
     private final ArrayList<FrameSlot> slots;
     private final HashMap<Object, FrameSlot> identifierToSlotMap;
     private Assumption version;
     private HashMap<Object, Assumption> identifierToNotInFrameAssumptionMap;
 
     public FrameDescriptor() {
-        this(DefaultFrameTypeConversion.getInstance());
+        this(null);
     }
 
-    public FrameDescriptor(FrameTypeConversion typeConversion) {
-        this.typeConversion = typeConversion;
+    public FrameDescriptor(Object defaultValue) {
+        this.defaultValue = defaultValue;
         slots = new ArrayList<>();
         identifierToSlotMap = new HashMap<>();
         version = createVersion();
     }
 
+    public static FrameDescriptor create() {
+        return new FrameDescriptor();
+    }
+
+    public static FrameDescriptor create(Object defaultValue) {
+        return new FrameDescriptor(defaultValue);
+    }
+
     public FrameSlot addFrameSlot(Object identifier) {
         return addFrameSlot(identifier, null, FrameSlotKind.Illegal);
     }
@@ -91,6 +98,14 @@
         return addFrameSlot(identifier, kind);
     }
 
+    public FrameSlot findOrAddFrameSlot(Object identifier, Object info, FrameSlotKind kind) {
+        FrameSlot result = findFrameSlot(identifier);
+        if (result != null) {
+            return result;
+        }
+        return addFrameSlot(identifier, info, kind);
+    }
+
     public void removeFrameSlot(Object identifier) {
         CompilerAsserts.neverPartOfCompilation("interpreter-only.  includes hashmap operations.");
         assert identifierToSlotMap.containsKey(identifier);
@@ -118,7 +133,7 @@
     }
 
     public FrameDescriptor copy() {
-        FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.typeConversion);
+        FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue);
         for (int i = 0; i < this.getSlots().size(); i++) {
             Object identifier = this.getSlots().get(i).getIdentifier();
             clonedFrameDescriptor.addFrameSlot(identifier);
@@ -127,7 +142,7 @@
     }
 
     public FrameDescriptor shallowCopy() {
-        FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.typeConversion);
+        FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue);
         clonedFrameDescriptor.slots.addAll(slots);
         clonedFrameDescriptor.identifierToSlotMap.putAll(identifierToSlotMap);
         return clonedFrameDescriptor;
@@ -146,8 +161,8 @@
         return Truffle.getRuntime().createAssumption("frame version");
     }
 
-    public FrameTypeConversion getTypeConversion() {
-        return typeConversion;
+    public Object getDefaultValue() {
+        return defaultValue;
     }
 
     public Assumption getNotInFrameAssumption(Object identifier) {
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameTypeConversion.java	Thu Oct 23 12:02:02 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.frame;
-
-/**
- * Interface for defining type conversions for frame slot values.
- */
-public interface FrameTypeConversion {
-
-    Object getDefaultValue();
-
-    void updateFrameSlot(Frame frame, FrameSlot slot, Object value);
-}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultFrameTypeConversion.java	Thu Oct 23 12:02:02 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.impl;
-
-import com.oracle.truffle.api.frame.*;
-
-/**
- * Interface for defining type conversions for frame slot values.
- */
-public class DefaultFrameTypeConversion implements FrameTypeConversion {
-
-    private static final DefaultFrameTypeConversion INSTANCE = new DefaultFrameTypeConversion();
-
-    @Override
-    public Object getDefaultValue() {
-        return null;
-    }
-
-    @Override
-    public void updateFrameSlot(Frame frame, FrameSlot slot, Object value) {
-        if (slot.getKind() != FrameSlotKind.Object) {
-            slot.setKind(FrameSlotKind.Object);
-        }
-        frame.setObject(slot, value);
-    }
-
-    public static DefaultFrameTypeConversion getInstance() {
-        return INSTANCE;
-    }
-}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java	Thu Oct 23 12:02:02 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java	Thu Oct 23 13:45:59 2014 +0200
@@ -45,7 +45,7 @@
         this.descriptor = descriptor;
         this.arguments = arguments;
         this.locals = new Object[descriptor.getSize()];
-        Arrays.fill(locals, descriptor.getTypeConversion().getDefaultValue());
+        Arrays.fill(locals, descriptor.getDefaultValue());
         this.tags = new byte[descriptor.getSize()];
     }
 
@@ -178,12 +178,6 @@
         }
         byte tag = tags[slotIndex];
         if (accessKind == FrameSlotKind.Object ? tag != 0 : tag != accessKind.ordinal()) {
-            if (slot.getKind() == accessKind || tag == 0) {
-                descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot));
-                if (tags[slotIndex] == accessKind.ordinal()) {
-                    return;
-                }
-            }
             throw new FrameSlotTypeException();
         }
     }
@@ -193,7 +187,7 @@
         int newSize = descriptor.getSize();
         if (newSize > oldSize) {
             locals = Arrays.copyOf(locals, newSize);
-            Arrays.fill(locals, oldSize, newSize, descriptor.getTypeConversion().getDefaultValue());
+            Arrays.fill(locals, oldSize, newSize, descriptor.getDefaultValue());
             tags = Arrays.copyOf(tags, newSize);
             return true;
         }