< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewArrayNode.java

Print this page




  81     private static native Object newArray(@ConstantNodeParameter Class<?> elementType, int length, @ConstantNodeParameter boolean fillContents);
  82 
  83     public static Object newUninitializedArray(Class<?> elementType, int length) {
  84         return newArray(elementType, length, false);
  85     }
  86 
  87     /**
  88      * Gets the element type of the array.
  89      *
  90      * @return the element type of the array
  91      */
  92     public ResolvedJavaType elementType() {
  93         return elementType;
  94     }
  95 
  96     @Override
  97     public void virtualize(VirtualizerTool tool) {
  98         ValueNode lengthAlias = tool.getAlias(length());
  99         if (lengthAlias.asConstant() != null) {
 100             int constantLength = lengthAlias.asJavaConstant().asInt();
 101             if (constantLength >= 0 && constantLength < tool.getMaximumEntryCount()) {
 102                 ValueNode[] state = new ValueNode[constantLength];
 103                 ConstantNode defaultForKind = constantLength == 0 ? null : defaultElementValue();
 104                 for (int i = 0; i < constantLength; i++) {
 105                     state[i] = defaultForKind;
 106                 }
 107                 VirtualObjectNode virtualObject = createVirtualArrayNode(constantLength);
 108                 tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode> emptyList(), false);
 109                 tool.replaceWithVirtual(virtualObject);
 110             }
 111         }
 112     }
 113 
 114     protected VirtualArrayNode createVirtualArrayNode(int constantLength) {
 115         return new VirtualArrayNode(elementType(), constantLength);
 116     }
 117 
 118     /* Factored out in a separate method so that subclasses can override it. */
 119     protected ConstantNode defaultElementValue() {
 120         return ConstantNode.defaultForKind(elementType().getJavaKind(), graph());
 121     }




  81     private static native Object newArray(@ConstantNodeParameter Class<?> elementType, int length, @ConstantNodeParameter boolean fillContents);
  82 
  83     public static Object newUninitializedArray(Class<?> elementType, int length) {
  84         return newArray(elementType, length, false);
  85     }
  86 
  87     /**
  88      * Gets the element type of the array.
  89      *
  90      * @return the element type of the array
  91      */
  92     public ResolvedJavaType elementType() {
  93         return elementType;
  94     }
  95 
  96     @Override
  97     public void virtualize(VirtualizerTool tool) {
  98         ValueNode lengthAlias = tool.getAlias(length());
  99         if (lengthAlias.asConstant() != null) {
 100             int constantLength = lengthAlias.asJavaConstant().asInt();
 101             if (constantLength >= 0 && constantLength <= tool.getMaximumEntryCount()) {
 102                 ValueNode[] state = new ValueNode[constantLength];
 103                 ConstantNode defaultForKind = constantLength == 0 ? null : defaultElementValue();
 104                 for (int i = 0; i < constantLength; i++) {
 105                     state[i] = defaultForKind;
 106                 }
 107                 VirtualObjectNode virtualObject = createVirtualArrayNode(constantLength);
 108                 tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode> emptyList(), false);
 109                 tool.replaceWithVirtual(virtualObject);
 110             }
 111         }
 112     }
 113 
 114     protected VirtualArrayNode createVirtualArrayNode(int constantLength) {
 115         return new VirtualArrayNode(elementType(), constantLength);
 116     }
 117 
 118     /* Factored out in a separate method so that subclasses can override it. */
 119     protected ConstantNode defaultElementValue() {
 120         return ConstantNode.defaultForKind(elementType().getJavaKind(), graph());
 121     }


< prev index next >