--- old/src/java.base/share/classes/jdk/internal/vm/VMSupport.java 2020-02-20 22:12:41.033361100 +0900 +++ new/src/java.base/share/classes/jdk/internal/vm/VMSupport.java 2020-02-20 22:12:40.749972200 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,13 +24,12 @@ */ package jdk.internal.vm; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Properties; -import java.util.Set; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.jar.Attributes; +import java.util.*; /* * Support class used by JVMTI and VM attach mechanism. @@ -50,25 +49,37 @@ } private static native Properties initAgentProperties(Properties props); + private static String convertToBytesStr(String str, boolean escapeSpace) throws Exception { + str = str.replace("\n", "\\n") + .replace("\r", "\\r") + .replace("\t", "\\t") + .replace("\f", "\\f"); + if (escapeSpace) { + str = str.replace(" ", "\\ "); + } + + String result = ""; + for (char ch : str.toCharArray()) { + result += ((ch < 0x20) || (ch > 0x7e)) ? String.format("\\u%04X", (int)ch) + : ch; + } + + return result; + } + /** * Write the given properties list to a byte array and return it. Properties with - * a key or value that is not a String is filtered out. The stream written to the byte - * array is ISO 8859-1 encoded. + * a key or value that is not a String is filtered out. */ private static byte[] serializePropertiesToByteArray(Properties p) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(4096); - - Properties props = new Properties(); - - // stringPropertyNames() returns a snapshot of the property keys - Set keyset = p.stringPropertyNames(); - for (String key : keyset) { - String value = p.getProperty(key); - props.put(key, value); + var joiner = new StringJoiner("\n"); + joiner.add((new Date()).toString()); + for (var entry : p.entrySet()) { + var key = convertToBytes(entry.getKey().toString(), true); + var value = convertToBytes(entry.getValue().toString(), false); + joiner.add(key + "=" + value); } - - props.store(out, null); - return out.toByteArray(); + return joiner.toString().getBytes(); } public static byte[] serializePropertiesToByteArray() throws IOException {