changeset 14417:093828a3a3ce

8259886: Improve SSL session cache performance and scalability Reviewed-by: erikj, xuelei, aph, mbalao Contributed-by: djelinski <djelinski1@gmail.com>
author xuelei
date Fri, 02 Apr 2021 17:51:43 +0800
parents a364726474e6
children 8f6f14c0c9ce
files src/share/classes/sun/security/util/Cache.java
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/util/Cache.java	Fri Nov 15 20:29:11 2019 +0100
+++ b/src/share/classes/sun/security/util/Cache.java	Fri Apr 02 17:51:43 2021 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2021, 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
@@ -252,6 +252,7 @@
     private final Map<K, CacheEntry<K,V>> cacheMap;
     private int maxSize;
     private long lifetime;
+    private long nextExpirationTime = Long.MAX_VALUE;
 
     // ReferenceQueue is of type V instead of Cache<K,V>
     // to allow SoftCacheEntry to extend SoftReference<V>
@@ -321,12 +322,18 @@
         }
         int cnt = 0;
         long time = System.currentTimeMillis();
+        if (nextExpirationTime > time) {
+            return;
+        }
+        nextExpirationTime = Long.MAX_VALUE;
         for (Iterator<CacheEntry<K,V>> t = cacheMap.values().iterator();
                 t.hasNext(); ) {
             CacheEntry<K,V> entry = t.next();
             if (entry.isValid(time) == false) {
                 t.remove();
                 cnt++;
+            } else if (nextExpirationTime > entry.getExpirationTime()) {
+                nextExpirationTime = entry.getExpirationTime();
             }
         }
         if (DEBUG) {
@@ -360,6 +367,9 @@
         emptyQueue();
         long expirationTime = (lifetime == 0) ? 0 :
                                         System.currentTimeMillis() + lifetime;
+        if (expirationTime < nextExpirationTime) {
+            nextExpirationTime = expirationTime;
+        }
         CacheEntry<K,V> newEntry = newEntry(key, value, expirationTime, queue);
         CacheEntry<K,V> oldEntry = cacheMap.put(key, newEntry);
         if (oldEntry != null) {
@@ -474,6 +484,7 @@
 
         V getValue();
 
+        long getExpirationTime();
     }
 
     private static class HardCacheEntry<K,V> implements CacheEntry<K,V> {
@@ -496,6 +507,10 @@
             return value;
         }
 
+        public long getExpirationTime() {
+            return expirationTime;
+        }
+
         public boolean isValid(long currentTime) {
             boolean valid = (currentTime <= expirationTime);
             if (valid == false) {
@@ -533,6 +548,10 @@
             return get();
         }
 
+        public long getExpirationTime() {
+            return expirationTime;
+        }
+
         public boolean isValid(long currentTime) {
             boolean valid = (currentTime <= expirationTime) && (get() != null);
             if (valid == false) {