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

Merge form KonaJDK 8.0.19 #144

Merged
merged 6 commits into from
Aug 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion common/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,4 @@ JRE_BUNDLE_DIR=$(IMAGES_OUTPUTDIR)/$(JRE_BUNDLE_SUBDIR)
# Include TencentJDK version information
DISTRO_NAME=Tencent Kona
COMPANY_NAME=Tencent
DISTRO_VERSION=8.0.18
DISTRO_VERSION=8.0.19
30 changes: 21 additions & 9 deletions hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,11 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {

if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
ex_name->as_C_string()));
RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s %s'",
ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;

if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
Expand All @@ -1080,9 +1082,11 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
the_class->link_class(THREAD);
if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
ex_name->as_C_string()));
RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s %s'",
ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;
if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
return JVMTI_ERROR_OUT_OF_MEMORY;
Expand Down Expand Up @@ -1118,9 +1122,11 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {

if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD,
("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
("verify_byte_codes exception: '%s %s'", ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;
if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
return JVMTI_ERROR_OUT_OF_MEMORY;
Expand All @@ -1133,9 +1139,11 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD,
("merge_cp_and_rewrite exception: '%s'", ex_name->as_C_string()));
("merge_cp_and_rewrite exception: '%s %s'", ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;
if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
return JVMTI_ERROR_OUT_OF_MEMORY;
Expand All @@ -1153,10 +1161,12 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {

if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD,
("verify_byte_codes post merge-CP exception: '%s'",
ex_name->as_C_string()));
("verify_byte_codes post merge-CP exception: '%s %s'",
ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;
if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
return JVMTI_ERROR_OUT_OF_MEMORY;
Expand All @@ -1173,9 +1183,11 @@ jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
}
if (HAS_PENDING_EXCEPTION) {
Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
oop msg = java_lang_Throwable::message(PENDING_EXCEPTION);
// RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
RC_TRACE_WITH_THREAD(0x00000002, THREAD,
("Rewriter::rewrite or link_methods exception: '%s'", ex_name->as_C_string()));
("Rewriter::rewrite or link_methods exception: '%s %s'", ex_name->as_C_string(),
(msg != NULL ? java_lang_String::as_utf8_string(msg) : "null")));
CLEAR_PENDING_EXCEPTION;
if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
return JVMTI_ERROR_OUT_OF_MEMORY;
Expand Down
82 changes: 82 additions & 0 deletions hotspot/test/runtime/RedefineTests/TestRedefineVerifyErrorLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2023, 2024 THL A29 Limited, a Tencent company. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test print more detail error message
* @library /testlibrary
* @build RedefineClassHelper
* @run main RedefineClassHelper
* @run main/othervm TestRedefineVerifyErrorLog
*/

import com.oracle.java.testlibrary.OutputAnalyzer;
import com.oracle.java.testlibrary.ProcessTools;
import com.oracle.java.testlibrary.InMemoryJavaCompiler;

class TestRedefineVerifyErrorLog_B {
static boolean b;
int faa() { System.out.println("orig"); return 1; }
}

public class TestRedefineVerifyErrorLog {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-javaagent:redefineagent.jar",
"-XX:TraceRedefineClasses=2",
"RedefineVerifyErrorLog");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
System.out.println(output.getOutput());
output.shouldContain("expected VerifyError");
output.shouldContain("VerifyError Bad type on operand stack");
}
}
class RedefineVerifyErrorLog {

static final String DEST = System.getProperty("test.classes");
static String newB =
"class TestRedefineVerifyErrorLog_B { " +
" static boolean b; " +
" int faa() { System.out.println(\"redefine\"); b = true; return 2; } " +
"}";

public static void main(String[] args) throws Exception {
Class<?> B = Class.forName("TestRedefineVerifyErrorLog_B");

try {
byte[] classBytes = InMemoryJavaCompiler.compile("TestRedefineVerifyErrorLog_B", newB);
// break classBytes
// find pattern B6 00 04 04 B3
// replace last 04 (iconst_1) with 0xe (dconst_0)
for (int i = 0; i < classBytes.length; i++) {
int cur = Byte.toUnsignedInt(classBytes[i]);
if (cur == 0xb6 && (i + 4 < classBytes.length)) {
int cur_3 = Byte.toUnsignedInt(classBytes[i+3]);
int cur_4 = Byte.toUnsignedInt(classBytes[i+4]);
if (cur_3 == 0x4 && cur_4 == 0xb3) {
System.out.println("found");
classBytes[i+3] = 0xe;
}
}
}
RedefineClassHelper.redefineClass(B, classBytes);
} catch (VerifyError e) {
System.out.println("expected VerifyError");
}
}
}
4 changes: 1 addition & 3 deletions jdk/src/share/classes/com/sun/crypto/provider/SMEntries.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2023, 2024, THL A29 Limited, a Tencent company. 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
Expand Down Expand Up @@ -28,8 +28,6 @@
final class SMEntries {

static void putEntries(Provider p) {
p.put("Cipher.SM2", "com.sun.crypto.provider.SM2Cipher");

p.put("Mac.HmacSM3", "com.sun.crypto.provider.HmacSM3");
p.put("KeyGenerator.HmacSM3", "com.sun.crypto.provider.HmacSM3KeyGenerator");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. 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
Expand All @@ -18,32 +18,39 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.sun.crypto.provider;
package sun.security.ec;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.CipherSpi;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;

import static java.math.BigInteger.ZERO;
import static java.security.spec.SM2ParameterSpec.ORDER;

import sun.security.ec.SM2PrivateKey;
import sun.security.ec.SM2PublicKey;
import sun.security.jca.JCAUtil;

/**
* SM2 cipher in compliance with GB/T 32918.4-2016.
Expand Down Expand Up @@ -75,7 +82,7 @@ public void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException {
buffer.reset();

SecureRandom rand = random != null ? random : SunJCE.getRandom();;
SecureRandom rand = random != null ? random : JCAUtil.getSecureRandom();;

if (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE) {
if (key instanceof ECPublicKey) {
Expand Down Expand Up @@ -248,3 +255,87 @@ public void reset() {
}
}
}

final class ConstructKeys {
/**
* Construct a public key from its encoding.
*
* @param encodedKey the encoding of a public key.
*
* @param encodedKeyAlgorithm the algorithm the encodedKey is for.
*
* @return a public key constructed from the encodedKey.
*/
private static final PublicKey constructPublicKey(byte[] encodedKey,
String encodedKeyAlgorithm)
throws InvalidKeyException, NoSuchAlgorithmException {
try {
KeyFactory keyFactory =
KeyFactory.getInstance(encodedKeyAlgorithm);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
return keyFactory.generatePublic(keySpec);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchAlgorithmException("No installed providers " +
"can create keys for the " +
encodedKeyAlgorithm +
"algorithm", nsae);
} catch (InvalidKeySpecException ike) {
throw new InvalidKeyException("Cannot construct public key", ike);
}
}

/**
* Construct a private key from its encoding.
*
* @param encodedKey the encoding of a private key.
*
* @param encodedKeyAlgorithm the algorithm the wrapped key is for.
*
* @return a private key constructed from the encodedKey.
*/
private static final PrivateKey constructPrivateKey(byte[] encodedKey,
String encodedKeyAlgorithm) throws InvalidKeyException,
NoSuchAlgorithmException {
try {
KeyFactory keyFactory =
KeyFactory.getInstance(encodedKeyAlgorithm);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
return keyFactory.generatePrivate(keySpec);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchAlgorithmException("No installed providers " +
"can create keys for the " +
encodedKeyAlgorithm +
"algorithm", nsae);
} catch (InvalidKeySpecException ike) {
throw new InvalidKeyException("Cannot construct private key", ike);
}
}

/**
* Construct a secret key from its encoding.
*
* @param encodedKey the encoding of a secret key.
*
* @param encodedKeyAlgorithm the algorithm the secret key is for.
*
* @return a secret key constructed from the encodedKey.
*/
private static final SecretKey constructSecretKey(byte[] encodedKey,
String encodedKeyAlgorithm) {
return new SecretKeySpec(encodedKey, encodedKeyAlgorithm);
}

static final Key constructKey(byte[] encoding, String keyAlgorithm,
int keyType) throws InvalidKeyException, NoSuchAlgorithmException {
switch (keyType) {
case Cipher.SECRET_KEY:
return constructSecretKey(encoding, keyAlgorithm);
case Cipher.PRIVATE_KEY:
return constructPrivateKey(encoding, keyAlgorithm);
case Cipher.PUBLIC_KEY:
return constructPublicKey(encoding, keyAlgorithm);
default:
throw new InvalidKeyException("Unknown keytype " + keyType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. 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
Expand All @@ -18,7 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package com.sun.crypto.provider;
package sun.security.ec;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
Expand Down
3 changes: 2 additions & 1 deletion jdk/src/share/classes/sun/security/ec/SMEntries.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2023, 2024, THL A29 Limited, a Tencent company. 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
Expand Down Expand Up @@ -28,6 +28,7 @@
final class SMEntries {

static void putEntries(Map<Object, Object> map) {
map.put("Cipher.SM2", "sun.security.ec.SM2Cipher");
map.put("KeyFactory.SM2", "sun.security.ec.SM2KeyFactory");
map.put("Signature.SM3withSM2", "sun.security.ec.SM2Signature");
map.put("Alg.Alias.Signature.SM2", "SM3withSM2");
Expand Down
Loading
Loading