comparison graal/com.oracle.truffle.object/src/com/oracle/truffle/object/ShapeImpl.java @ 18795:e9cbe1618733

Truffle: refactor size calculation in location allocator to visitor pattern
author Andreas Woess <andreas.woess@jku.at>
date Wed, 07 Jan 2015 15:11:38 +0100
parents 6db7923af642
children 068256ee3b90
comparison
equal deleted inserted replaced
18794:e688e42b41e3 18795:e9cbe1618733
29 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; 29 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
30 import com.oracle.truffle.api.interop.*; 30 import com.oracle.truffle.api.interop.*;
31 import com.oracle.truffle.api.nodes.*; 31 import com.oracle.truffle.api.nodes.*;
32 import com.oracle.truffle.api.object.*; 32 import com.oracle.truffle.api.object.*;
33 import com.oracle.truffle.api.utilities.*; 33 import com.oracle.truffle.api.utilities.*;
34 import com.oracle.truffle.object.LocationImpl.InternalLongLocation; 34 import com.oracle.truffle.object.LocationImpl.*;
35 import com.oracle.truffle.object.Locations.ConstantLocation; 35 import com.oracle.truffle.object.Locations.ConstantLocation;
36 import com.oracle.truffle.object.Locations.DeclaredDualLocation; 36 import com.oracle.truffle.object.Locations.DeclaredDualLocation;
37 import com.oracle.truffle.object.Locations.DeclaredLocation; 37 import com.oracle.truffle.object.Locations.DeclaredLocation;
38 import com.oracle.truffle.object.Locations.DualLocation; 38 import com.oracle.truffle.object.Locations.DualLocation;
39 import com.oracle.truffle.object.Locations.ValueLocation; 39 import com.oracle.truffle.object.Locations.ValueLocation;
952 @Override 952 @Override
953 public Shape tryMerge(Shape other) { 953 public Shape tryMerge(Shape other) {
954 return null; 954 return null;
955 } 955 }
956 956
957 public abstract static class BaseAllocator extends Allocator { 957 public abstract static class BaseAllocator extends Allocator implements LocationVisitor {
958 protected final LayoutImpl layout; 958 protected final LayoutImpl layout;
959 protected int objectArraySize; 959 protected int objectArraySize;
960 protected int objectFieldSize; 960 protected int objectFieldSize;
961 protected int primitiveFieldSize; 961 protected int primitiveFieldSize;
962 protected int primitiveArraySize; 962 protected int primitiveArraySize;
1054 } 1054 }
1055 1055
1056 protected <T extends Location> T advance(T location0) { 1056 protected <T extends Location> T advance(T location0) {
1057 if (location0 instanceof LocationImpl) { 1057 if (location0 instanceof LocationImpl) {
1058 LocationImpl location = (LocationImpl) location0; 1058 LocationImpl location = (LocationImpl) location0;
1059 objectArraySize += location.objectArrayCount(); 1059 if (location != layout.getPrimitiveArrayLocation()) {
1060 primitiveArraySize += location.primitiveArrayCount(); 1060 location.accept(this);
1061 primitiveFieldSize += location.primitiveFieldCount(); 1061 }
1062 if (layout.hasPrimitiveExtensionArray()) { 1062 if (layout.hasPrimitiveExtensionArray()) {
1063 hasPrimitiveArray |= location == layout.getPrimitiveArrayLocation() || location.primitiveArrayCount() != 0; 1063 hasPrimitiveArray |= location == layout.getPrimitiveArrayLocation() || primitiveArraySize > 0;
1064 objectFieldSize = location == layout.getPrimitiveArrayLocation() ? objectFieldSize : Math.max(objectFieldSize, layout.objectFieldIndex(location) + location.objectFieldCount());
1065 } else { 1064 } else {
1066 assert !hasPrimitiveArray && location.primitiveArrayCount() == 0; 1065 assert !hasPrimitiveArray && primitiveArraySize == 0;
1067 objectFieldSize += location.objectFieldCount();
1068 } 1066 }
1069 } 1067 }
1070 depth++; 1068 depth++;
1071 return location0; 1069 return location0;
1072 } 1070 }
1074 @Override 1072 @Override
1075 public BaseAllocator addLocation(Location location) { 1073 public BaseAllocator addLocation(Location location) {
1076 advance(location); 1074 advance(location);
1077 return this; 1075 return this;
1078 } 1076 }
1077
1078 public void visitObjectField(int index, int count) {
1079 objectFieldSize = Math.max(objectFieldSize, index + count);
1080 }
1081
1082 public void visitObjectArray(int index, int count) {
1083 objectArraySize = Math.max(objectArraySize, index + count);
1084 }
1085
1086 public void visitPrimitiveArray(int index, int count) {
1087 primitiveArraySize = Math.max(primitiveArraySize, index + count);
1088 }
1089
1090 public void visitPrimitiveField(int index, int count) {
1091 primitiveFieldSize = Math.max(primitiveFieldSize, index + count);
1092 }
1079 } 1093 }
1080 1094
1081 private static void debugRegisterShape(ShapeImpl newShape) { 1095 private static void debugRegisterShape(ShapeImpl newShape) {
1082 if (ObjectStorageOptions.DumpShapes) { 1096 if (ObjectStorageOptions.DumpShapes) {
1083 Debug.registerShape(newShape); 1097 Debug.registerShape(newShape);