Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-58622] Compact binary encoding for ObjectCopier. #9959

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package jdk.graal.compiler.util.test;

import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -175,20 +176,14 @@ public void testIt() {
List<Field> externalValueFields = List.of(ObjectCopier.getField(BaseClass.class, "BASE_SINGLETON"),
ObjectCopier.getField(TestObject.class, "TEST_OBJECT_SINGLETON"));

String encoded = ObjectCopier.encode(new ObjectCopier.Encoder(externalValueFields), root);
if (DEBUG) {
System.out.printf("encoded:%n%s%n", encoded);
}
byte[] encoded = encode(externalValueFields, root, "encoded");
Object decoded = ObjectCopier.decode(encoded, loader);
if (DEBUG) {
System.out.printf("root:%n%s%n", root);
System.out.printf("decoded:%n%s%n", decoded);
}
String reencoded = ObjectCopier.encode(new ObjectCopier.Encoder(externalValueFields), decoded);
if (DEBUG) {
System.out.printf("reencoded:%n%s%n", reencoded);
}
Assert.assertEquals(encoded, reencoded);
byte[] reencoded = encode(externalValueFields, decoded, "reencoded");
Assert.assertArrayEquals(encoded, reencoded);

Map<String, Object> root2 = (Map<String, Object>) ObjectCopier.decode(reencoded, loader);

Expand All @@ -201,6 +196,15 @@ public void testIt() {
Assert.assertSame(root2.get("singleton2"), root2.get("singleton2_2"));
}

private static byte[] encode(List<Field> externalValueFields, Object root, String debugLabel) {
PrintStream debugStream = null;
if (DEBUG) {
debugStream = System.out;
debugStream.printf("%s:%n", debugLabel);
}
return ObjectCopier.encode(new ObjectCopier.Encoder(externalValueFields, debugStream), root);
}

@Test
public void test() throws IOException, InterruptedException {
launchSubprocess(this::testIt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import jdk.graal.compiler.core.ArchitectureSpecific;
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
import org.graalvm.collections.EconomicMap;

import jdk.graal.compiler.core.ArchitectureSpecific;
import jdk.graal.compiler.core.common.spi.ForeignCallSignature;
import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.debug.TTY;
import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.hotspot.CompilerConfigurationFactory;
import jdk.graal.compiler.hotspot.EncodedSnippets;
import jdk.graal.compiler.hotspot.HotSpotForeignCallLinkage;
import jdk.graal.compiler.hotspot.HotSpotReplacementsImpl;
Expand Down Expand Up @@ -148,7 +148,7 @@ public static void configureGraalForLibGraal(String arch,
Consumer<Class<?>> registerAsInHeap,
Consumer<List<Class<?>>> hostedGraalSetFoldNodePluginClasses,
String nativeImageLocationQualifier,
String encodedGuestObjects) {
byte[] encodedGuestObjects) {
GraalError.guarantee(VALID_LOADER_NAME.equals(LOADER.getName()),
"Only call this method from classloader " + VALID_LOADER_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ protected ClassInfo makeClassInfo(Class<?> declaringClass) {
return ci;
}
};
String encoded = ObjectCopier.encode(encoder, encodedObjects);
byte[] encoded = ObjectCopier.encode(encoder, encodedObjects);

Files.writeString(Path.of(args[0]), encoded);
Files.write(Path.of(args[0]), encoded);
}

private static EncodedSnippets getEncodedSnippets(HotSpotReplacementsImpl replacements, OptionValues options) {
Expand Down
Loading