mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8270317: Large Allocation in CipherSuite
Reviewed-by: xuelei, simonis
This commit is contained in:
parent
0dcfc42f23
commit
e627caec84
2 changed files with 106 additions and 60 deletions
|
@ -25,12 +25,8 @@
|
||||||
|
|
||||||
package sun.security.ssl;
|
package sun.security.ssl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import static sun.security.ssl.CipherSuite.HashAlg.*;
|
import static sun.security.ssl.CipherSuite.HashAlg.*;
|
||||||
import static sun.security.ssl.CipherSuite.KeyExchange.*;
|
import static sun.security.ssl.CipherSuite.KeyExchange.*;
|
||||||
import static sun.security.ssl.CipherSuite.MacAlg.*;
|
import static sun.security.ssl.CipherSuite.MacAlg.*;
|
||||||
|
@ -857,6 +853,39 @@ enum CipherSuite {
|
||||||
|
|
||||||
final boolean exportable;
|
final boolean exportable;
|
||||||
|
|
||||||
|
private static final Map<Integer, CipherSuite> cipherSuiteIds;
|
||||||
|
private static final Map<String, CipherSuite> cipherSuiteNames;
|
||||||
|
private static final List<CipherSuite> allowedCipherSuites;
|
||||||
|
private static final List<CipherSuite> defaultCipherSuites;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Map<Integer, CipherSuite> ids = new HashMap<>();
|
||||||
|
Map<String, CipherSuite> names = new HashMap<>();
|
||||||
|
List<CipherSuite> allowedCS = new ArrayList<>();
|
||||||
|
List<CipherSuite> defaultCS = new ArrayList<>();
|
||||||
|
|
||||||
|
for(CipherSuite cs : CipherSuite.values()) {
|
||||||
|
ids.put(cs.id, cs);
|
||||||
|
names.put(cs.name, cs);
|
||||||
|
for (String alias : cs.aliases) {
|
||||||
|
names.put(alias, cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cs.supportedProtocols.isEmpty()) {
|
||||||
|
allowedCS.add(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cs.isDefaultEnabled) {
|
||||||
|
defaultCS.add(cs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cipherSuiteIds = Map.copyOf(ids);
|
||||||
|
cipherSuiteNames = Map.copyOf(names);
|
||||||
|
allowedCipherSuites = List.copyOf(allowedCS);
|
||||||
|
defaultCipherSuites = List.copyOf(defaultCS);
|
||||||
|
}
|
||||||
|
|
||||||
// known but unsupported cipher suite
|
// known but unsupported cipher suite
|
||||||
private CipherSuite(String name, int id) {
|
private CipherSuite(String name, int id) {
|
||||||
this(id, false, name, "",
|
this(id, false, name, "",
|
||||||
|
@ -894,62 +923,29 @@ enum CipherSuite {
|
||||||
}
|
}
|
||||||
|
|
||||||
static CipherSuite nameOf(String ciperSuiteName) {
|
static CipherSuite nameOf(String ciperSuiteName) {
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
return cipherSuiteNames.get(ciperSuiteName);
|
||||||
if (cs.name.equals(ciperSuiteName) ||
|
|
||||||
cs.aliases.contains(ciperSuiteName)) {
|
|
||||||
return cs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static CipherSuite valueOf(int id) {
|
static CipherSuite valueOf(int id) {
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
return cipherSuiteIds.get(id);
|
||||||
if (cs.id == id) {
|
|
||||||
return cs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String nameOf(int id) {
|
static String nameOf(int id) {
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
CipherSuite cs = cipherSuiteIds.get(id);
|
||||||
if (cs.id == id) {
|
|
||||||
return cs.name;
|
if (cs != null) {
|
||||||
}
|
return cs.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "UNKNOWN-CIPHER-SUITE(" + Utilities.byte16HexString(id) + ")";
|
return "UNKNOWN-CIPHER-SUITE(" + Utilities.byte16HexString(id) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
static Collection<CipherSuite> allowedCipherSuites() {
|
static Collection<CipherSuite> allowedCipherSuites() {
|
||||||
Collection<CipherSuite> cipherSuites = new LinkedList<>();
|
return allowedCipherSuites;
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
|
||||||
if (!cs.supportedProtocols.isEmpty()) {
|
|
||||||
cipherSuites.add(cs);
|
|
||||||
} else {
|
|
||||||
// values() is ordered, remaining cipher suites are
|
|
||||||
// not supported.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cipherSuites;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Collection<CipherSuite> defaultCipherSuites() {
|
static Collection<CipherSuite> defaultCipherSuites() {
|
||||||
Collection<CipherSuite> cipherSuites = new LinkedList<>();
|
return defaultCipherSuites;
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
|
||||||
if (cs.isDefaultEnabled) {
|
|
||||||
cipherSuites.add(cs);
|
|
||||||
} else {
|
|
||||||
// values() is ordered, remaining cipher suites are
|
|
||||||
// not enabled.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cipherSuites;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -972,19 +968,11 @@ enum CipherSuite {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (CipherSuite cs : CipherSuite.values()) {
|
CipherSuite cs;
|
||||||
if (!cs.supportedProtocols.isEmpty()) {
|
if ((cs = cipherSuiteNames.get(name)) != null
|
||||||
if (cs.name.equals(name) ||
|
&& !cs.supportedProtocols.isEmpty()) {
|
||||||
cs.aliases.contains(name)) {
|
cipherSuites.add(cs);
|
||||||
cipherSuites.add(cs);
|
found = true;
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// values() is ordered, remaining cipher suites are
|
|
||||||
// not supported.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright Amazon.com Inc. 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
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.openjdk.bench.java.security;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
|
@Fork(jvmArgsAppend = {"--add-exports", "java.base/sun.security.ssl=ALL-UNNAMED", "--add-opens", "java.base/sun.security.ssl=ALL-UNNAMED"})
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||||
|
@BenchmarkMode(Mode.Throughput)
|
||||||
|
public class CipherSuiteBench {
|
||||||
|
|
||||||
|
Method nameOf;
|
||||||
|
|
||||||
|
@Param({"TLS_AES_256_GCM_SHA384",
|
||||||
|
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
|
||||||
|
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
|
||||||
|
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA" })
|
||||||
|
String cipherSuite;
|
||||||
|
|
||||||
|
@Setup
|
||||||
|
public void initilizeClass() throws ClassNotFoundException, NoSuchMethodException {
|
||||||
|
Class<?> cs = Class.forName("sun.security.ssl.CipherSuite");
|
||||||
|
nameOf = cs.getDeclaredMethod("nameOf", String.class);
|
||||||
|
nameOf.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public Object benchmarkCipherSuite() throws InvocationTargetException, IllegalAccessException {
|
||||||
|
return nameOf.invoke(null,cipherSuite);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue