Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed Jul 31, 2024
2 parents 93b333a + 56bf7be commit 07cc7c6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2023, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -54,7 +54,6 @@
import com.oracle.svm.hosted.c.info.SizableInfo;
import com.oracle.svm.hosted.c.info.StructFieldInfo;
import com.oracle.svm.hosted.c.info.StructInfo;
import com.oracle.svm.hosted.lambda.LambdaSubstitutionType;
import com.oracle.svm.hosted.meta.HostedField;
import com.oracle.svm.hosted.meta.HostedMetaAccess;
import com.oracle.svm.hosted.meta.HostedMethod;
Expand Down Expand Up @@ -171,12 +170,13 @@ protected static ResolvedJavaType getDeclaringClass(HostedField hostedField, boo
}

protected static ResolvedJavaType getOriginal(HostedType hostedType) {
/* partially unwrap then traverse through substitutions to the original */
/*
* partially unwrap then traverse through substitutions to the original. We don't want to
* get the original type of LambdaSubstitutionType to keep the stable name
*/
ResolvedJavaType javaType = hostedType.getWrapped().getWrapped();
if (javaType instanceof SubstitutionType) {
return ((SubstitutionType) javaType).getOriginal();
} else if (javaType instanceof LambdaSubstitutionType) {
return ((LambdaSubstitutionType) javaType).getOriginal();
} else if (javaType instanceof InjectedFieldsType) {
return ((InjectedFieldsType) javaType).getOriginal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
*/
package com.oracle.svm.test.debug.helper;

import com.oracle.svm.core.NeverInline;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import com.oracle.svm.core.NeverInline;

public class PrettyPrinterTest {

Expand Down Expand Up @@ -135,6 +136,12 @@ static void testHashMap(HashMap<String, String> strMap, Map<Object, Object> mixe
System.out.print("");
}

@SuppressWarnings("unused")
@NeverInline("For testing purposes")
static void testLambda(Function<String, String> lambda) {
System.out.print("");
}

static ExampleClass setupExampleObject(boolean recursive) {
ExampleClass example = new ExampleClass();
example.f10 = new ExampleClass(10, 20, (short) 30, '\40', (byte) 50, true, "60", Day.Sunday, new Object(), null);
Expand Down Expand Up @@ -163,5 +170,7 @@ public static void main(String[] args) {
testArrayList(new ArrayList<>(List.of("this", "is", "a", "string", "list")), new ArrayList<>(List.of(1, 2L, "string")), nullList);
testHashMap(new HashMap<>(Map.of("this", "one", "is", "two", "a", "three", "string", "four", "list", "five")),
new HashMap<>(Map.of(1, new ExampleClass(), 2L, "string", (byte) 3, new ArrayList<>())));

testLambda(str -> str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def gdb_output(var: str, output_format: str = None) -> str:
return gdb_execute('output{} {}'.format("" if output_format is None else "/" + output_format, var))


def gdb_print_type(t: str) -> str:
logger.info(f'Print type {t}')
return gdb_execute(f'ptype {t}')


def gdb_print(var: str, output_format: str = None) -> str:
logger.info(f'Print variable {var}')
return gdb_execute('print{} {}'.format("" if output_format is None else "/" + output_format, var))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,20 @@ def test_mixed_hash_map(self):
self.assertIn('[3] = java.util.ArrayList(0) = {...}', exec_string)
self.assertTrue(exec_string.endswith('}'))

def test_lambda_type(self):
gdb_set_breakpoint("com.oracle.svm.test.debug.helper.PrettyPrinterTest::testLambda")
gdb_run()
type_name = gdb_output("(('java.lang.Object' *)lambda).hub.name").strip('"') # strip enclosing quotes
try:
exec_string = gdb_print_type(f"'{type_name}'")
print(type_name)
print(exec_string)
self.assertFalse(exec_string.startswith('No symbol'), "Lambda runtime type names do not match lambda type symbol names")
self.assertTrue(exec_string.startswith(f'type = class {type_name}'), f"GDB output: '{exec_string}'")
self.assertIn('java.lang.Object * apply(java.lang.Object *);', exec_string) # check for function
except Exception:
self.fail("Lambda runtime type names do not match lambda type symbol names")


# redirect unittest output to terminal
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.__stdout__))

0 comments on commit 07cc7c6

Please sign in to comment.