Skip to content

Commit

Permalink
Add tests for large array support
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmoldrich committed Nov 12, 2019
1 parent 410b8d4 commit 56407d8
Show file tree
Hide file tree
Showing 4 changed files with 685 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface BufferConverter {
buffer.putShort(s);
};

ByteBuffer buffer = constantArrayToBuffer(value, isElementType, converter);
ByteBuffer buffer = constantArrayToBuffer(value, isElementType, converter, 2);
if (buffer == null) return null;
LocalVar var = injectLoadableResource(mv, resourceWriter, buffer, "shortArrayFromResource");
GimpleArrayType arrayType = (GimpleArrayType) value.getType();
Expand All @@ -71,7 +71,7 @@ interface BufferConverter {
buffer.putDouble(d);
};

ByteBuffer buffer = constantArrayToBuffer(value, isElementType, converter);
ByteBuffer buffer = constantArrayToBuffer(value, isElementType, converter, 8);
if (buffer == null) return null;
LocalVar var = injectLoadableResource(mv, resourceWriter, buffer, "doubleArrayFromResource");
GimpleArrayType arrayType = (GimpleArrayType) value.getType();
Expand Down Expand Up @@ -187,7 +187,8 @@ public void load(@Nonnull MethodGenerator mv) {
private static ByteBuffer constantArrayToBuffer(
GimpleConstructor value,
Predicate<GimpleType> isElementType,
BufferConverter converter
BufferConverter converter,
int byteSize
) {
boolean isArrayType = isArrayWithType(value.getType(), isElementType);
if (!isArrayType) {
Expand All @@ -197,7 +198,7 @@ private static ByteBuffer constantArrayToBuffer(
if (elements.size() < 4000) { // only stream large arrays
return null;
}
ByteBuffer buffer = ByteBuffer.allocate(elements.size() * 2).order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer buffer = ByteBuffer.allocate(elements.size() * byteSize).order(ByteOrder.LITTLE_ENDIAN);
for (GimpleConstructor.Element element : elements) {
converter.append(buffer, element);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ public void arrayC() throws Exception {
result = (Integer) testPointer.invoke(null);

assertThat(result, equalTo(42));

result = (Integer)clazz.getMethod("testLargeShortArray").invoke(null);
assertTrue("Very large short arrays not handled correctly", result != 0);

result = (Integer)clazz.getMethod("testLargeDoubleArray").invoke(null);
assertTrue("Very large double arrays not handled correctly", result != 0);
}

@Test
Expand Down Expand Up @@ -784,7 +790,7 @@ public void uninitializedVariables() throws Exception {
// InitDataFlowAnalysis analysis = new InitDataFlowAnalysis(function, cfg);
// analysis.solve();
// analysis.dump();
//
//
// System.out.println("Variables requiring initialization: " + analysis.getVariablesUsedWithoutInitialization());

Class<?> clazz = compile("uninit.c");
Expand Down Expand Up @@ -924,7 +930,7 @@ public void clockTest() throws Exception {

@Test
public void endpointClass() throws Exception {
// Plugin was segfaulting
// Plugin was segfaulting
Class<?> endpoints = compile("endpoint.cpp");

Method allocMethod = endpoints.getMethod("alloc_endpoints");
Expand Down Expand Up @@ -990,41 +996,41 @@ public void unionArrayPrimitiveMixed() throws Exception {
public void unionArrayPrimitiveMixed2() throws Exception {
compileAndTest("union_arrays2.c");
}

@Test
public void fortranCommonBlocks() throws Exception {
Class<?> commonBlocks = compile("common.f");

Method sub1 = commonBlocks.getMethod("sub1_");

sub1.invoke(null);
}

@Test
public void funptrFields() throws Exception {
compileAndTest("funptr_fields.c");
}

@Test
public void recordArrayFields() throws Exception {
compileAndTest("record_array_fields.c");
compileAndTest("record_array_fields.c");
}

@Test
public void voidPtrSet() throws Exception {
compileAndTest("void_ptr_set.c");
}

@Test
public void addressableFieldMemSet() throws Exception {
compileAndTest("addr_field_memset.c");
}

@Test
public void zeroLengthArrayFields() throws Exception {
compileAndTest("zero_array_fields.c");
}

@Test
public void fatPtrFieldParamAssign() throws Exception {
compileAndTest("fatptrfield_param_assign.c");
Expand Down
Loading

0 comments on commit 56407d8

Please sign in to comment.