!55 Merge branch 'master' into 20.03-LTS

From: @jvmboy
Reviewed-by: @jdkboy
Signed-off-by: @jdkboy
This commit is contained in:
openeuler-ci-bot 2020-12-31 10:17:38 +08:00 committed by Gitee
commit 4244bbede2
8 changed files with 10341 additions and 2 deletions

View File

@ -0,0 +1,168 @@
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
index 5a1d3b900..ab327bf9a 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
@@ -2471,6 +2471,9 @@ public class ClassReader {
}
private List<Type> adjustMethodParams(long flags, List<Type> args) {
+ if (args.isEmpty()) {
+ return args;
+ }
boolean isVarargs = (flags & VARARGS) != 0;
if (isVarargs) {
Type varargsElem = args.last();
diff --git a/test/langtools/tools/javac/AvoidNPEAtClassReader/AvoidNPEAtClassReaderTest.java b/test/langtools/tools/javac/AvoidNPEAtClassReader/AvoidNPEAtClassReaderTest.java
new file mode 100644
index 000000000..3b47d6944
--- /dev/null
+++ b/test/langtools/tools/javac/AvoidNPEAtClassReader/AvoidNPEAtClassReaderTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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.
+ */
+
+/**
+ * @test
+ * @bug 8207160
+ * @summary ClassReader::adjustMethodParams can potentially return null if the args list is empty
+ * @compile pkg/Outer.jasm pkg/Outer$Inner.jasm AvoidNPEAtClassReaderTest.java
+ */
+
+
+/** this test is checking that javac doesn't fail with NPE when reading inner classes with constructors
+ * that doesn't have as a parameter a reference to the outer class. Such constructors were generated by
+ * versions of javac previous to JDK7.
+ */
+
+import pkg.*;
+
+public class AvoidNPEAtClassReaderTest {
+ public void bar(Outer outer) {
+ Object stuff = outer.foo();
+ }
+}
diff --git a/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer$Inner.jasm b/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer$Inner.jasm
new file mode 100644
index 000000000..23fe2eb4b
--- /dev/null
+++ b/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer$Inner.jasm
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 pkg;
+
+super public final class Outer$Inner
+ version 55:0
+{
+
+final synthetic Field this$0:"Lpkg/Outer;";
+
+public Method "<init>":"()V"
+ stack 1 locals 1
+{
+ aload_0;
+ invokespecial Method java/lang/Object."<init>":"()V";
+ return;
+}
+
+public final InnerClass Inner=class Outer$Inner of class Outer;
+
+} // end Class Outer$Inner
diff --git a/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer.jasm b/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer.jasm
new file mode 100644
index 000000000..13baaf761
--- /dev/null
+++ b/test/langtools/tools/javac/AvoidNPEAtClassReader/pkg/Outer.jasm
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 pkg;
+
+super public class Outer
+ version 55:0
+{
+
+
+public Method "<init>":"()V"
+ stack 1 locals 1
+{
+ aload_0;
+ invokespecial Method java/lang/Object."<init>":"()V";
+ return;
+}
+
+public Method foo:"()Lpkg/Outer$Inner;"
+ stack 1 locals 1
+{
+ aconst_null;
+ areturn;
+}
+
+public final InnerClass Inner=class Outer$Inner of class Outer;
+
+} // end Class Outer
--
2.19.1

View File

@ -0,0 +1,399 @@
diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
index 3749a99bb..ef8fb4ac0 100644
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, 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
@@ -2202,7 +2202,10 @@ void G1CMTask::reset(G1CMBitMap* next_mark_bitmap) {
}
bool G1CMTask::should_exit_termination() {
- regular_clock_call();
+ if (!regular_clock_call()) {
+ return true;
+ }
+
// This is called when we are in the termination protocol. We should
// quit if, for some reason, this task wants to abort or the global
// stack is not empty (this means that we can get work from it).
@@ -2213,12 +2216,12 @@ void G1CMTask::reached_limit() {
assert(_words_scanned >= _words_scanned_limit ||
_refs_reached >= _refs_reached_limit ,
"shouldn't have been called otherwise");
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
}
-void G1CMTask::regular_clock_call() {
+bool G1CMTask::regular_clock_call() {
if (has_aborted()) {
- return;
+ return false;
}
// First, we need to recalculate the words scanned and refs reached
@@ -2229,21 +2232,19 @@ void G1CMTask::regular_clock_call() {
// (1) If an overflow has been flagged, then we abort.
if (_cm->has_overflown()) {
- set_has_aborted();
- return;
+ return false;
}
// If we are not concurrent (i.e. we're doing remark) we don't need
// to check anything else. The other steps are only needed during
// the concurrent marking phase.
if (!_cm->concurrent()) {
- return;
+ return true;
}
// (2) If marking has been aborted for Full GC, then we also abort.
if (_cm->has_aborted()) {
- set_has_aborted();
- return;
+ return false;
}
double curr_time_ms = os::elapsedVTime() * 1000.0;
@@ -2252,17 +2253,15 @@ void G1CMTask::regular_clock_call() {
if (SuspendibleThreadSet::should_yield()) {
// We should yield. To do this we abort the task. The caller is
// responsible for yielding.
- set_has_aborted();
- return;
+ return false;
}
// (5) We check whether we've reached our time quota. If we have,
// then we abort.
double elapsed_time_ms = curr_time_ms - _start_time_ms;
if (elapsed_time_ms > _time_target_ms) {
- set_has_aborted();
_has_timed_out = true;
- return;
+ return false;
}
// (6) Finally, we check whether there are enough completed STAB
@@ -2271,9 +2270,9 @@ void G1CMTask::regular_clock_call() {
if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) {
// we do need to process SATB buffers, we'll abort and restart
// the marking task to do so
- set_has_aborted();
- return;
+ return false;
}
+ return true;
}
void G1CMTask::recalculate_limits() {
@@ -2428,7 +2427,7 @@ void G1CMTask::drain_satb_buffers() {
// until we run out of buffers or we need to abort.
while (!has_aborted() &&
satb_mq_set.apply_closure_to_completed_buffer(&satb_cl)) {
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
}
_draining_satb_buffers = false;
@@ -2671,7 +2670,7 @@ void G1CMTask::do_marking_step(double time_target_ms,
// If the iteration is successful, give up the region.
if (mr.is_empty()) {
giveup_current_region();
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
} else if (_curr_region->is_humongous() && mr.start() == _curr_region->bottom()) {
if (_next_mark_bitmap->is_marked(mr.start())) {
// The object is marked - apply the closure
@@ -2680,10 +2679,10 @@ void G1CMTask::do_marking_step(double time_target_ms,
// Even if this task aborted while scanning the humongous object
// we can (and should) give up the current region.
giveup_current_region();
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
} else if (_next_mark_bitmap->iterate(&bitmap_closure, mr)) {
giveup_current_region();
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
} else {
assert(has_aborted(), "currently the only way to do so");
// The only way to abort the bitmap iteration is to return
@@ -2738,7 +2737,7 @@ void G1CMTask::do_marking_step(double time_target_ms,
// block of empty regions. So we need to call the regular clock
// method once round the loop to make sure it's called
// frequently enough.
- regular_clock_call();
+ abort_marking_if_regular_check_fail();
}
if (!has_aborted() && _curr_region == NULL) {
@@ -2816,6 +2815,7 @@ void G1CMTask::do_marking_step(double time_target_ms,
guarantee(_cm->mark_stack_empty(), "only way to reach here");
guarantee(_task_queue->size() == 0, "only way to reach here");
guarantee(!_cm->has_overflown(), "only way to reach here");
+ guarantee(!has_aborted(), "should never happen if termination has completed");
} else {
// Apparently there's more work to do. Let's abort this task. It
// will restart it and we can hopefully find more things to do.
diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
index b5eb26197..b760fe977 100644
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
@@ -730,7 +730,11 @@ private:
// Supposed to be called regularly during a marking step as
// it checks a bunch of conditions that might cause the marking step
// to abort
- void regular_clock_call();
+ // Return true if the marking step should continue. Otherwise, return false to abort
+ bool regular_clock_call();
+
+ // Set abort flag if regular_clock_call() check fails
+ inline void abort_marking_if_regular_check_fail();
// Test whether obj might have already been passed over by the
// mark bitmap scan, and so needs to be pushed onto the mark stack.
diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp
index 4a969c511..383cdc563 100644
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp
@@ -210,6 +210,12 @@ inline void G1ConcurrentMark::add_to_liveness(uint worker_id, oop const obj, siz
task(worker_id)->update_liveness(obj, size);
}
+inline void G1CMTask::abort_marking_if_regular_check_fail() {
+ if (!regular_clock_call()) {
+ set_has_aborted();
+ }
+}
+
inline bool G1CMTask::make_reference_grey(oop obj) {
if (!_cm->mark_in_next_bitmap(_worker_id, obj)) {
return false;
diff --git a/src/hotspot/share/gc/shared/owstTaskTerminator.cpp b/src/hotspot/share/gc/shared/owstTaskTerminator.cpp
index 3c32ab627..2856a9981 100644
--- a/src/hotspot/share/gc/shared/owstTaskTerminator.cpp
+++ b/src/hotspot/share/gc/shared/owstTaskTerminator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
*
* 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
@@ -38,15 +38,17 @@ bool OWSTTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
// Single worker, done
if (_n_threads == 1) {
_offered_termination = 1;
+ assert(!peek_in_queue_set(), "Precondition");
return true;
}
_blocker->lock_without_safepoint_check();
- // All arrived, done
_offered_termination++;
+ // All arrived, done
if (_offered_termination == _n_threads) {
_blocker->notify_all();
_blocker->unlock();
+ assert(!peek_in_queue_set(), "Precondition");
return true;
}
@@ -59,21 +61,31 @@ bool OWSTTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
if (do_spin_master_work(terminator)) {
assert(_offered_termination == _n_threads, "termination condition");
+ assert(!peek_in_queue_set(), "Precondition");
return true;
} else {
_blocker->lock_without_safepoint_check();
+ // There is possibility that termination is reached between dropping the lock
+ // before returning from do_spin_master_work() and acquiring lock above.
+ if (_offered_termination == _n_threads) {
+ _blocker->unlock();
+ assert(!peek_in_queue_set(), "Precondition");
+ return true;
+ }
}
} else {
_blocker->wait(true, WorkStealingSleepMillis);
if (_offered_termination == _n_threads) {
_blocker->unlock();
+ assert(!peek_in_queue_set(), "Precondition");
return true;
}
}
size_t tasks = tasks_in_queue_set();
if (exit_termination(tasks, terminator)) {
+ assert_lock_strong(_blocker);
_offered_termination--;
_blocker->unlock();
return false;
@@ -153,19 +165,24 @@ bool OWSTTaskTerminator::do_spin_master_work(TerminatorTerminator* terminator) {
_total_peeks++;
#endif
size_t tasks = tasks_in_queue_set();
- if (exit_termination(tasks, terminator)) {
+ bool exit = exit_termination(tasks, terminator);
+ {
MonitorLockerEx locker(_blocker, Mutex::_no_safepoint_check_flag);
- if (tasks >= _offered_termination - 1) {
- locker.notify_all();
- } else {
- for (; tasks > 1; tasks--) {
- locker.notify();
+ // Termination condition reached
+ if (_offered_termination == _n_threads) {
+ _spin_master = NULL;
+ return true;
+ } else if (exit) {
+ if (tasks >= _offered_termination - 1) {
+ locker.notify_all();
+ } else {
+ for (; tasks > 1; tasks--) {
+ locker.notify();
+ }
}
+ _spin_master = NULL;
+ return false;
}
- _spin_master = NULL;
- return false;
- } else if (_offered_termination == _n_threads) {
- return true;
}
}
}
diff --git a/src/hotspot/share/gc/shared/owstTaskTerminator.hpp b/src/hotspot/share/gc/shared/owstTaskTerminator.hpp
index 9e6fe135a..190033eb7 100644
--- a/src/hotspot/share/gc/shared/owstTaskTerminator.hpp
+++ b/src/hotspot/share/gc/shared/owstTaskTerminator.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
*
* 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
@@ -55,6 +55,7 @@ public:
}
virtual ~OWSTTaskTerminator() {
+ assert(_spin_master == NULL, "Should have been reset");
assert(_blocker != NULL, "Can not be NULL");
delete _blocker;
}
diff --git a/src/hotspot/share/gc/shared/taskqueue.cpp b/src/hotspot/share/gc/shared/taskqueue.cpp
index 47639bdf9..697c13645 100644
--- a/src/hotspot/share/gc/shared/taskqueue.cpp
+++ b/src/hotspot/share/gc/shared/taskqueue.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, 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
@@ -25,6 +25,9 @@
#include "precompiled.hpp"
#include "gc/shared/taskqueue.hpp"
#include "gc/shared/owstTaskTerminator.hpp"
+#if INCLUDE_SHENANDOAHGC
+#include "gc/shenandoah/shenandoahHeap.hpp"
+#endif
#include "oops/oop.inline.hpp"
#include "logging/log.hpp"
#include "runtime/atomic.hpp"
@@ -118,6 +121,14 @@ ParallelTaskTerminator(uint n_threads, TaskQueueSetSuper* queue_set) :
_queue_set(queue_set),
_offered_termination(0) {}
+ParallelTaskTerminator::~ParallelTaskTerminator() {
+ assert(_offered_termination == 0 || !peek_in_queue_set(), "Precondition");
+#if INCLUDE_SHENANDOAHGC
+ if (UseShenandoahGC && ShenandoahHeap::heap()->cancelled_gc()) return;
+#endif
+ assert(_offered_termination == 0 || _offered_termination == _n_threads, "Terminated or aborted" );
+}
+
bool ParallelTaskTerminator::peek_in_queue_set() {
return _queue_set->peek();
}
@@ -162,6 +173,7 @@ ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
assert(_offered_termination <= _n_threads, "Invariant");
// Are all threads offering termination?
if (_offered_termination == _n_threads) {
+ assert(!peek_in_queue_set(), "Precondition");
return true;
} else {
// Look for more work.
@@ -211,9 +223,7 @@ ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
#endif
if (peek_in_queue_set() ||
(terminator != NULL && terminator->should_exit_termination())) {
- Atomic::dec(&_offered_termination);
- assert(_offered_termination < _n_threads, "Invariant");
- return false;
+ return complete_or_exit_termination();
}
}
}
@@ -229,6 +239,23 @@ void ParallelTaskTerminator::print_termination_counts() {
}
#endif
+bool ParallelTaskTerminator::complete_or_exit_termination() {
+ // If termination is ever reached, terminator should stay in such state,
+ // so that all threads see the same state
+ uint current_offered = _offered_termination;
+ uint expected_value;
+ do {
+ if (current_offered == _n_threads) {
+ assert(!peek_in_queue_set(), "Precondition");
+ return true;
+ }
+ expected_value = current_offered;
+ } while ((current_offered = Atomic::cmpxchg(current_offered - 1, &_offered_termination, current_offered)) != expected_value);
+
+ assert(_offered_termination < _n_threads, "Invariant");
+ return false;
+}
+
void ParallelTaskTerminator::reset_for_reuse() {
if (_offered_termination != 0) {
assert(_offered_termination == _n_threads,
diff --git a/src/hotspot/share/gc/shared/taskqueue.hpp b/src/hotspot/share/gc/shared/taskqueue.hpp
index 1b60a62c2..110757684 100644
--- a/src/hotspot/share/gc/shared/taskqueue.hpp
+++ b/src/hotspot/share/gc/shared/taskqueue.hpp
@@ -491,11 +491,18 @@ protected:
virtual void yield();
void sleep(uint millis);
+ // Called when exiting termination is requested.
+ // When the request is made, terminator may have already terminated
+ // (e.g. all threads are arrived and offered termination). In this case,
+ // it should ignore the request and complete the termination.
+ // Return true if termination is completed. Otherwise, return false.
+ bool complete_or_exit_termination();
public:
// "n_threads" is the number of threads to be terminated. "queue_set" is a
// queue sets of work queues of other threads.
ParallelTaskTerminator(uint n_threads, TaskQueueSetSuper* queue_set);
+ virtual ~ParallelTaskTerminator();
// The current thread has no work, and is ready to terminate if everyone
// else is. If returns "true", all threads are terminated. If returns
--
2.19.1

View File

@ -0,0 +1,479 @@
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java
index d1b9d06d8..82d0dc164 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11AEADCipher.java
@@ -1,4 +1,5 @@
-/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+/*
+ * Copyright (c) 2019, 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
@@ -334,25 +335,25 @@ final class P11AEADCipher extends CipherSpi {
}
private void cancelOperation() {
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ int bufLen = doFinalLength(0);
+ byte[] buffer = new byte[bufLen];
+ byte[] in = dataBuffer.toByteArray();
+ int inLen = in.length;
try {
- if (session.hasObjects() == false) {
- session = token.killSession(session);
- return;
+ if (encrypt) {
+ token.p11.C_Encrypt(session.id(), 0, in, 0, inLen,
+ 0, buffer, 0, bufLen);
} else {
- // cancel operation by finishing it
- int bufLen = doFinalLength(0);
- byte[] buffer = new byte[bufLen];
-
- if (encrypt) {
- token.p11.C_Encrypt(session.id(), 0, buffer, 0, bufLen,
- 0, buffer, 0, bufLen);
- } else {
- token.p11.C_Decrypt(session.id(), 0, buffer, 0, bufLen,
- 0, buffer, 0, bufLen);
- }
+ token.p11.C_Decrypt(session.id(), 0, in, 0, inLen,
+ 0, buffer, 0, bufLen);
}
} catch (PKCS11Exception e) {
- throw new ProviderException("Cancel failed", e);
+ if (encrypt) {
+ throw new ProviderException("Cancel failed", e);
+ }
+ // ignore failure for decryption
}
}
@@ -434,18 +435,21 @@ final class P11AEADCipher extends CipherSpi {
if (!initialized) {
return;
}
+ initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
} finally {
p11Key.releaseKeyID();
session = token.releaseSession(session);
+ dataBuffer.reset();
}
- initialized = false;
}
// see JCE spec
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java
index cc4535e7b..470a888cd 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -409,10 +409,12 @@ final class P11Cipher extends CipherSpi {
return;
}
initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
@@ -426,22 +428,21 @@ final class P11Cipher extends CipherSpi {
private void cancelOperation() {
token.ensureValid();
- if (session.hasObjects() == false) {
- session = token.killSession(session);
- return;
- } else {
- try {
- // cancel operation by finishing it
- int bufLen = doFinalLength(0);
- byte[] buffer = new byte[bufLen];
- if (encrypt) {
- token.p11.C_EncryptFinal(session.id(), 0, buffer, 0, bufLen);
- } else {
- token.p11.C_DecryptFinal(session.id(), 0, buffer, 0, bufLen);
- }
- } catch (PKCS11Exception e) {
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ try {
+ int bufLen = doFinalLength(0);
+ byte[] buffer = new byte[bufLen];
+ if (encrypt) {
+ token.p11.C_EncryptFinal(session.id(), 0, buffer, 0, bufLen);
+ } else {
+ token.p11.C_DecryptFinal(session.id(), 0, buffer, 0, bufLen);
+ }
+ } catch (PKCS11Exception e) {
+ if (encrypt) {
throw new ProviderException("Cancel failed", e);
}
+ // ignore failure for decryption
}
}
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Mac.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Mac.java
index 338cb215d..634e0855f 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Mac.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Mac.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -124,10 +124,12 @@ final class P11Mac extends MacSpi {
return;
}
initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
@@ -139,15 +141,12 @@ final class P11Mac extends MacSpi {
private void cancelOperation() {
token.ensureValid();
- if (session.hasObjects() == false) {
- session = token.killSession(session);
- return;
- } else {
- try {
- token.p11.C_SignFinal(session.id(), 0);
- } catch (PKCS11Exception e) {
- throw new ProviderException("Cancel failed", e);
- }
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ try {
+ token.p11.C_SignFinal(session.id(), 0);
+ } catch (PKCS11Exception e) {
+ throw new ProviderException("Cancel failed", e);
}
}
@@ -209,7 +208,6 @@ final class P11Mac extends MacSpi {
ensureInitialized();
return token.p11.C_SignFinal(session.id(), 0);
} catch (PKCS11Exception e) {
- reset(true);
throw new ProviderException("doFinal() failed", e);
} finally {
reset(false);
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java
index 763fb98a8..0a470b932 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11PSSSignature.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 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
@@ -223,10 +223,12 @@ final class P11PSSSignature extends SignatureSpi {
return;
}
initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
@@ -242,14 +244,10 @@ final class P11PSSSignature extends SignatureSpi {
token.ensureValid();
if (DEBUG) System.out.print("Cancelling operation");
- if (session.hasObjects() == false) {
- if (DEBUG) System.out.println(" by killing session");
- session = token.killSession(session);
- return;
- }
- // "cancel" operation by finishing it
- if (mode == M_SIGN) {
- try {
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ try {
+ if (mode == M_SIGN) {
if (type == T_UPDATE) {
if (DEBUG) System.out.println(" by C_SignFinal");
token.p11.C_SignFinal(session.id(), 0);
@@ -259,11 +257,7 @@ final class P11PSSSignature extends SignatureSpi {
if (DEBUG) System.out.println(" by C_Sign");
token.p11.C_Sign(session.id(), digest);
}
- } catch (PKCS11Exception e) {
- throw new ProviderException("cancel failed", e);
- }
- } else { // M_VERIFY
- try {
+ } else { // M_VERIFY
byte[] signature =
new byte[(p11Key.length() + 7) >> 3];
if (type == T_UPDATE) {
@@ -275,10 +269,12 @@ final class P11PSSSignature extends SignatureSpi {
if (DEBUG) System.out.println(" by C_Verify");
token.p11.C_Verify(session.id(), digest, signature);
}
- } catch (PKCS11Exception e) {
- // will fail since the signature is incorrect
- // XXX check error code
}
+ } catch (PKCS11Exception e) {
+ if (mode == M_SIGN) {
+ throw new ProviderException("cancel failed", e);
+ }
+ // ignore failure for verification
}
}
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSACipher.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSACipher.java
index 3f32501e0..06d65e893 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSACipher.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSACipher.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -247,10 +247,12 @@ final class P11RSACipher extends CipherSpi {
return;
}
initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
@@ -264,36 +266,33 @@ final class P11RSACipher extends CipherSpi {
// state variables such as "initialized"
private void cancelOperation() {
token.ensureValid();
- if (session.hasObjects() == false) {
- session = token.killSession(session);
- return;
- } else {
- try {
- PKCS11 p11 = token.p11;
- int inLen = maxInputSize;
- int outLen = buffer.length;
- long sessId = session.id();
- switch (mode) {
- case MODE_ENCRYPT:
- p11.C_Encrypt(sessId, 0, buffer, 0, inLen, 0, buffer, 0, outLen);
- break;
- case MODE_DECRYPT:
- p11.C_Decrypt(sessId, 0, buffer, 0, inLen, 0, buffer, 0, outLen);
- break;
- case MODE_SIGN:
- byte[] tmpBuffer = new byte[maxInputSize];
- p11.C_Sign(sessId, tmpBuffer);
- break;
- case MODE_VERIFY:
- p11.C_VerifyRecover(sessId, buffer, 0, inLen, buffer,
- 0, outLen);
- break;
- default:
- throw new ProviderException("internal error");
- }
- } catch (PKCS11Exception e) {
- // XXX ensure this always works, ignore error
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ try {
+ PKCS11 p11 = token.p11;
+ int inLen = maxInputSize;
+ int outLen = buffer.length;
+ long sessId = session.id();
+ switch (mode) {
+ case MODE_ENCRYPT:
+ p11.C_Encrypt(sessId, 0, buffer, 0, inLen, 0, buffer, 0, outLen);
+ break;
+ case MODE_DECRYPT:
+ p11.C_Decrypt(sessId, 0, buffer, 0, inLen, 0, buffer, 0, outLen);
+ break;
+ case MODE_SIGN:
+ byte[] tmpBuffer = new byte[maxInputSize];
+ p11.C_Sign(sessId, tmpBuffer);
+ break;
+ case MODE_VERIFY:
+ p11.C_VerifyRecover(sessId, buffer, 0, inLen, buffer,
+ 0, outLen);
+ break;
+ default:
+ throw new ProviderException("internal error");
}
+ } catch (PKCS11Exception e) {
+ // XXX ensure this always works, ignore error
}
}
@@ -362,6 +361,7 @@ final class P11RSACipher extends CipherSpi {
private int implDoFinal(byte[] out, int outOfs, int outLen)
throws BadPaddingException, IllegalBlockSizeException {
if (bufOfs > maxInputSize) {
+ reset(true);
throw new IllegalBlockSizeException("Data must not be longer "
+ "than " + maxInputSize + " bytes");
}
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java
index 159c65f59..f41538cda 100644
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -270,10 +270,12 @@ final class P11Signature extends SignatureSpi {
return;
}
initialized = false;
+
try {
if (session == null) {
return;
}
+
if (doCancel && token.explicitCancel) {
cancelOperation();
}
@@ -284,59 +286,51 @@ final class P11Signature extends SignatureSpi {
}
private void cancelOperation() {
-
token.ensureValid();
- if (session.hasObjects() == false) {
- session = token.killSession(session);
- return;
- } else {
- // "cancel" operation by finishing it
- // XXX make sure all this always works correctly
+ // cancel operation by finishing it; avoid killSession as some
+ // hardware vendors may require re-login
+ try {
if (mode == M_SIGN) {
- try {
- if (type == T_UPDATE) {
- token.p11.C_SignFinal(session.id(), 0);
- } else {
- byte[] digest;
- if (type == T_DIGEST) {
- digest = md.digest();
- } else { // T_RAW
- digest = buffer;
- }
- token.p11.C_Sign(session.id(), digest);
+ if (type == T_UPDATE) {
+ token.p11.C_SignFinal(session.id(), 0);
+ } else {
+ byte[] digest;
+ if (type == T_DIGEST) {
+ digest = md.digest();
+ } else { // T_RAW
+ digest = buffer;
}
- } catch (PKCS11Exception e) {
- throw new ProviderException("cancel failed", e);
+ token.p11.C_Sign(session.id(), digest);
}
} else { // M_VERIFY
byte[] signature;
- try {
- if (keyAlgorithm.equals("DSA")) {
- signature = new byte[40];
- } else {
- signature = new byte[(p11Key.length() + 7) >> 3];
- }
- if (type == T_UPDATE) {
- token.p11.C_VerifyFinal(session.id(), signature);
- } else {
- byte[] digest;
- if (type == T_DIGEST) {
- digest = md.digest();
- } else { // T_RAW
- digest = buffer;
- }
- token.p11.C_Verify(session.id(), digest, signature);
- }
- } catch (PKCS11Exception e) {
- long errorCode = e.getErrorCode();
- if ((errorCode == CKR_SIGNATURE_INVALID) ||
- (errorCode == CKR_SIGNATURE_LEN_RANGE)) {
- // expected since signature is incorrect
- return;
+ if (keyAlgorithm.equals("DSA")) {
+ signature = new byte[40];
+ } else {
+ signature = new byte[(p11Key.length() + 7) >> 3];
+ }
+ if (type == T_UPDATE) {
+ token.p11.C_VerifyFinal(session.id(), signature);
+ } else {
+ byte[] digest;
+ if (type == T_DIGEST) {
+ digest = md.digest();
+ } else { // T_RAW
+ digest = buffer;
}
- throw new ProviderException("cancel failed", e);
+ token.p11.C_Verify(session.id(), digest, signature);
+ }
+ }
+ } catch (PKCS11Exception e) {
+ if (mode == M_VERIFY) {
+ long errorCode = e.getErrorCode();
+ if ((errorCode == CKR_SIGNATURE_INVALID) ||
+ (errorCode == CKR_SIGNATURE_LEN_RANGE)) {
+ // expected since signature is incorrect
+ return;
}
}
+ throw new ProviderException("cancel failed", e);
}
}
--
2.19.1

View File

@ -0,0 +1,257 @@
diff --git a/src/hotspot/cpu/aarch64/assembler_aarch64.hpp b/src/hotspot/cpu/aarch64/assembler_aarch64.hpp
index db582f25f..80ddb9b31 100644
--- a/src/hotspot/cpu/aarch64/assembler_aarch64.hpp
+++ b/src/hotspot/cpu/aarch64/assembler_aarch64.hpp
@@ -553,14 +553,7 @@ class Address {
void lea(MacroAssembler *, Register) const;
- static bool offset_ok_for_immed(long offset, int shift = 0) {
- unsigned mask = (1 << shift) - 1;
- if (offset < 0 || offset & mask) {
- return (uabs(offset) < (1 << (20 - 12))); // Unscaled offset
- } else {
- return ((offset >> shift) < (1 << (21 - 10 + 1))); // Scaled, unsigned offset
- }
- }
+ static bool offset_ok_for_immed(long offset, uint shift);
};
// Convience classes
diff --git a/src/hotspot/cpu/aarch64/assembler_aarch64.inline.hpp b/src/hotspot/cpu/aarch64/assembler_aarch64.inline.hpp
index 86eb8c2f8..a475575bf 100644
--- a/src/hotspot/cpu/aarch64/assembler_aarch64.inline.hpp
+++ b/src/hotspot/cpu/aarch64/assembler_aarch64.inline.hpp
@@ -30,4 +30,15 @@
#include "asm/codeBuffer.hpp"
#include "code/codeCache.hpp"
+inline bool Address::offset_ok_for_immed(long offset, uint shift = 0) {
+ uint mask = (1 << shift) - 1;
+ if (offset < 0 || (offset & mask) != 0) {
+ // Unscaled signed offset, encoded in a signed imm9 field.
+ return Assembler::is_simm9(offset);
+ } else {
+ // Scaled unsigned offset, encoded in an unsigned imm12:_ field.
+ return Assembler::is_uimm12(offset >> shift);
+ }
+}
+
#endif // CPU_AARCH64_VM_ASSEMBLER_AARCH64_INLINE_HPP
diff --git a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
index f6a77dc78..7798aa509 100644
--- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
@@ -226,6 +226,19 @@ Address LIR_Assembler::as_Address_lo(LIR_Address* addr) {
// FIXME: This needs to be much more clever. See x86.
}
+// Ensure a valid Address (base + offset) to a stack-slot. If stack access is
+// not encodable as a base + (immediate) offset, generate an explicit address
+// calculation to hold the address in a temporary register.
+Address LIR_Assembler::stack_slot_address(int index, uint size, Register tmp, int adjust) {
+ precond(size == 4 || size == 8);
+ Address addr = frame_map()->address_for_slot(index, adjust);
+ precond(addr.getMode() == Address::base_plus_offset);
+ precond(addr.base() == sp);
+ precond(addr.offset() > 0);
+ uint mask = size - 1;
+ assert((addr.offset() & mask) == 0, "scaled offsets only");
+ return __ legitimize_address(addr, size, tmp);
+}
void LIR_Assembler::osr_entry() {
offsets()->set_value(CodeOffsets::OSR_Entry, code_offset());
@@ -745,32 +758,38 @@ void LIR_Assembler::reg2reg(LIR_Opr src, LIR_Opr dest) {
}
void LIR_Assembler::reg2stack(LIR_Opr src, LIR_Opr dest, BasicType type, bool pop_fpu_stack) {
+ precond(src->is_register() && dest->is_stack());
+
+ uint const c_sz32 = sizeof(uint32_t);
+ uint const c_sz64 = sizeof(uint64_t);
+
if (src->is_single_cpu()) {
+ int index = dest->single_stack_ix();
if (type == T_ARRAY || type == T_OBJECT) {
- __ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
+ __ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
__ verify_oop(src->as_register());
} else if (type == T_METADATA || type == T_DOUBLE || type == T_ADDRESS) {
- __ str(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
+ __ str(src->as_register(), stack_slot_address(index, c_sz64, rscratch1));
} else {
- __ strw(src->as_register(), frame_map()->address_for_slot(dest->single_stack_ix()));
+ __ strw(src->as_register(), stack_slot_address(index, c_sz32, rscratch1));
}
} else if (src->is_double_cpu()) {
- Address dest_addr_LO = frame_map()->address_for_slot(dest->double_stack_ix(), lo_word_offset_in_bytes);
+ int index = dest->double_stack_ix();
+ Address dest_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
__ str(src->as_register_lo(), dest_addr_LO);
} else if (src->is_single_fpu()) {
- Address dest_addr = frame_map()->address_for_slot(dest->single_stack_ix());
- __ strs(src->as_float_reg(), dest_addr);
+ int index = dest->single_stack_ix();
+ __ strs(src->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
} else if (src->is_double_fpu()) {
- Address dest_addr = frame_map()->address_for_slot(dest->double_stack_ix());
- __ strd(src->as_double_reg(), dest_addr);
+ int index = dest->double_stack_ix();
+ __ strd(src->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
} else {
ShouldNotReachHere();
}
-
}
@@ -855,32 +874,34 @@ void LIR_Assembler::reg2mem(LIR_Opr src, LIR_Opr dest, BasicType type, LIR_Patch
void LIR_Assembler::stack2reg(LIR_Opr src, LIR_Opr dest, BasicType type) {
- assert(src->is_stack(), "should not call otherwise");
- assert(dest->is_register(), "should not call otherwise");
+ precond(src->is_stack() && dest->is_register());
+
+ uint const c_sz32 = sizeof(uint32_t);
+ uint const c_sz64 = sizeof(uint64_t);
if (dest->is_single_cpu()) {
+ int index = src->single_stack_ix();
if (type == T_ARRAY || type == T_OBJECT) {
- __ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
+ __ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
__ verify_oop(dest->as_register());
} else if (type == T_METADATA || type == T_ADDRESS) {
- __ ldr(dest->as_register(), frame_map()->address_for_slot(src->single_stack_ix()));
+ __ ldr(dest->as_register(), stack_slot_address(index, c_sz64, rscratch1));
} else {
- Address src_addr = frame_map()->address_for_slot(src->single_stack_ix());
- Address data_addr = __ form_address(rscratch1, sp, src_addr.offset(), 2);
- __ ldrw(dest->as_register(), data_addr);
+ __ ldrw(dest->as_register(), stack_slot_address(index, c_sz32, rscratch1));
}
} else if (dest->is_double_cpu()) {
- Address src_addr_LO = frame_map()->address_for_slot(src->double_stack_ix(), lo_word_offset_in_bytes);
+ int index = src->double_stack_ix();
+ Address src_addr_LO = stack_slot_address(index, c_sz64, rscratch1, lo_word_offset_in_bytes);
__ ldr(dest->as_register_lo(), src_addr_LO);
} else if (dest->is_single_fpu()) {
- Address src_addr = frame_map()->address_for_slot(src->single_stack_ix());
- __ ldrs(dest->as_float_reg(), src_addr);
+ int index = src->single_stack_ix();
+ __ ldrs(dest->as_float_reg(), stack_slot_address(index, c_sz32, rscratch1));
} else if (dest->is_double_fpu()) {
- Address src_addr = frame_map()->address_for_slot(src->double_stack_ix());
- __ ldrd(dest->as_double_reg(), src_addr);
+ int index = src->double_stack_ix();
+ __ ldrd(dest->as_double_reg(), stack_slot_address(index, c_sz64, rscratch1));
} else {
ShouldNotReachHere();
diff --git a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.hpp b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.hpp
index 6374a33e6..9db81fed9 100644
--- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.hpp
+++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.hpp
@@ -45,10 +45,12 @@ friend class ArrayCopyStub;
bool is_literal_address(LIR_Address* addr);
- // When we need to use something other than rscratch1 use this
- // method.
+ // When we need to use something other than rscratch1 use this method.
Address as_Address(LIR_Address* addr, Register tmp);
+ // Ensure we have a valid Address (base+offset) to a stack-slot.
+ Address stack_slot_address(int index, uint shift, Register tmp, int adjust = 0);
+
// Record the type of the receiver in ReceiverTypeData
void type_profile_helper(Register mdo,
ciMethodData *md, ciProfileData *data,
diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
index 44497ea7c..014a4d3c6 100644
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
@@ -26,7 +26,7 @@
#ifndef CPU_AARCH64_VM_MACROASSEMBLER_AARCH64_HPP
#define CPU_AARCH64_VM_MACROASSEMBLER_AARCH64_HPP
-#include "asm/assembler.hpp"
+#include "asm/assembler.inline.hpp"
// MacroAssembler extends Assembler by frequently used macros.
//
@@ -132,6 +132,20 @@ class MacroAssembler: public Assembler {
a.lea(this, r);
}
+ /* Sometimes we get misaligned loads and stores, usually from Unsafe
+ accesses, and these can exceed the offset range. */
+ Address legitimize_address(const Address &a, int size, Register scratch) {
+ if (a.getMode() == Address::base_plus_offset) {
+ if (! Address::offset_ok_for_immed(a.offset(), exact_log2(size))) {
+ block_comment("legitimize_address {");
+ lea(scratch, a);
+ block_comment("} legitimize_address");
+ return Address(scratch);
+ }
+ }
+ return a;
+ }
+
void addmw(Address a, Register incr, Register scratch) {
ldrw(scratch, a);
addw(scratch, scratch, incr);
diff --git a/src/hotspot/share/asm/assembler.hpp b/src/hotspot/share/asm/assembler.hpp
index da181b90b..56c3068e4 100644
--- a/src/hotspot/share/asm/assembler.hpp
+++ b/src/hotspot/share/asm/assembler.hpp
@@ -302,6 +302,7 @@ class AbstractAssembler : public ResourceObj {
// Define some:
static bool is_simm5( intptr_t x) { return is_simm(x, 5 ); }
static bool is_simm8( intptr_t x) { return is_simm(x, 8 ); }
+ static bool is_simm9( intptr_t x) { return is_simm(x, 9 ); }
static bool is_simm10(intptr_t x) { return is_simm(x, 10); }
static bool is_simm11(intptr_t x) { return is_simm(x, 11); }
static bool is_simm12(intptr_t x) { return is_simm(x, 12); }
@@ -310,6 +311,15 @@ class AbstractAssembler : public ResourceObj {
static bool is_simm26(intptr_t x) { return is_simm(x, 26); }
static bool is_simm32(intptr_t x) { return is_simm(x, 32); }
+ // Test if x is within unsigned immediate range for width.
+ static bool is_uimm(intptr_t x, uint w) {
+ precond(0 < w && w < 64);
+ intptr_t limes = intptr_t(1) << w;
+ return x < limes;
+ }
+
+ static bool is_uimm12(intptr_t x) { return is_uimm(x, 12); }
+
// Accessors
CodeSection* code_section() const { return _code_section; }
CodeBuffer* code() const { return code_section()->outer(); }
diff --git a/src/hotspot/share/utilities/debug.hpp b/src/hotspot/share/utilities/debug.hpp
index aa594754a..c66c710f2 100644
--- a/src/hotspot/share/utilities/debug.hpp
+++ b/src/hotspot/share/utilities/debug.hpp
@@ -66,6 +66,9 @@ do { \
// For backward compatibility.
#define assert(p, ...) vmassert(p, __VA_ARGS__)
+#define precond(p) assert(p, "precond")
+#define postcond(p) assert(p, "postcond")
+
#ifndef ASSERT
#define vmassert_status(p, status, msg)
#else
--
2.19.1

8263
add-SVE-backend-feature.patch Executable file

File diff suppressed because it is too large Load Diff

413
add-integerCache-feature.patch Executable file
View File

@ -0,0 +1,413 @@
diff --git a/src/hotspot/share/prims/unsafe.cpp b/src/hotspot/share/prims/unsafe.cpp
index d8f1679b4..18ea89b85 100644
--- a/src/hotspot/share/prims/unsafe.cpp
+++ b/src/hotspot/share/prims/unsafe.cpp
@@ -1018,7 +1018,11 @@ UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleAr
return ret;
} UNSAFE_END
+UNSAFE_ENTRY(jboolean, Unsafe_GetUseHashMapIntegerCache(JNIEnv *env, jobject unsafe)) {
+ return UseHashMapIntegerCache;
+}
+UNSAFE_END
UNSAFE_ENTRY(jboolean, Unsafe_GetUseFastSerializer(JNIEnv *env, jobject unsafe)) {
return UseFastSerializer;
}
@@ -1108,6 +1113,7 @@ static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = {
{CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)},
{CC "isBigEndian0", CC "()Z", FN_PTR(Unsafe_isBigEndian0)},
+ {CC "getUseHashMapIntegerCache", CC "()Z", FN_PTR(Unsafe_GetUseHashMapIntegerCache)},
{CC "getUseFastSerializer", CC "()Z", FN_PTR(Unsafe_GetUseFastSerializer)},
{CC "unalignedAccess0", CC "()Z", FN_PTR(Unsafe_unalignedAccess0)}
};
diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp
index 47458b6c1..b8c0bec40 100644
--- a/src/hotspot/share/runtime/globals.hpp
+++ b/src/hotspot/share/runtime/globals.hpp
@@ -2677,6 +2677,11 @@ define_pd_global(uint64_t,MaxRAM, 1ULL*G);
JFR_ONLY(product(ccstr, StartFlightRecording, NULL, \
"Start flight recording with options")) \
\
+ experimental(bool, UseHashMapIntegerCache, false, \
+ "The integer cache is an array of references to objects of" \
+ "the HashMap Value type, indexed by the unboxed int key value." \
+ "faster in execution, higher in memory consumption.") \
+ \
experimental(bool, UseFastSerializer, false, \
"Cache-based serialization.It is extremely fast, but it can only" \
"be effective in certain scenarios.") \
diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java
index df303031a..c260b61fd 100644
--- a/src/java.base/share/classes/java/util/HashMap.java
+++ b/src/java.base/share/classes/java/util/HashMap.java
@@ -35,6 +35,7 @@ import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import jdk.internal.misc.SharedSecrets;
+import jdk.internal.misc.Unsafe;
/**
* Hash table based implementation of the {@code Map} interface. This
@@ -272,6 +273,28 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*/
static final int MIN_TREEIFY_CAPACITY = 64;
+ /**
+ * Used to get the commandline option: UseHashMapIntegerCache.
+ */
+ private static final Unsafe UNSAFE = Unsafe.getUnsafe();
+
+ /**
+ * Indicate integerCache can be performed. disable if HashMap.Node.setValue
+ * is directly used to update Node value.
+ */
+ private static boolean enableIntegerCache = UNSAFE.getUseHashMapIntegerCache();
+
+ /**
+ * The smallest table size for create integer cache.
+ */
+ private static final int MIN_INTEGER_CACHE = 2048;
+
+ /**
+ * The factor used in create integer cache to guarantee most Key are
+ * Integer and in range.
+ */
+ private static final float INTEGER_CACHE_FACTOR = 0.95f;
+
/**
* Basic hash bin node, used for most entries. (See below for
* TreeNode subclass, and in LinkedHashMap for its Entry subclass.)
@@ -298,6 +321,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
}
public final V setValue(V newValue) {
+ // Disable integerCache in all HashMap instance.
+ if (key != null && key instanceof Integer) {
+ enableIntegerCache = false;
+ }
V oldValue = value;
value = newValue;
return oldValue;
@@ -390,6 +417,12 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*/
transient Node<K,V>[] table;
+ /**
+ * Cache <Integer key -> Value> Map
+ * integerCache[key->intValue] = V
+ */
+ transient Object[] integerCache;
+
/**
* Holds cached entrySet(). Note that AbstractMap fields are used
* for keySet() and values().
@@ -547,7 +580,20 @@ public class HashMap<K,V> extends AbstractMap<K,V>
*
* @see #put(Object, Object)
*/
+ @SuppressWarnings("unchecked")
public V get(Object key) {
+ if (integerCache != null) {
+ if (enableIntegerCache == false) {
+ integerCache = null;
+ }
+ else if (key != null && key instanceof Integer) {
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < integerCache.length) {
+ return (V)integerCache[val];
+ }
+ }
+ }
+
Node<K,V> e;
return (e = getNode(hash(key), key)) == null ? null : e.value;
}
@@ -588,6 +634,17 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* key.
*/
public boolean containsKey(Object key) {
+ if (integerCache != null) {
+ if (enableIntegerCache == false) {
+ integerCache = null;
+ }
+ else if (key != null && key instanceof Integer) {
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < integerCache.length && integerCache[val] != null) {
+ return true;
+ }
+ }
+ }
return getNode(hash(key), key) != null;
}
@@ -620,6 +677,11 @@ public class HashMap<K,V> extends AbstractMap<K,V>
final V putVal(int hash, K key, V value, boolean onlyIfAbsent,
boolean evict) {
Node<K,V>[] tab; Node<K,V> p; int n, i;
+
+ if (integerCache != null) {
+ updateIntegerCache(key, value, onlyIfAbsent);
+ }
+
if ((tab = table) == null || (n = tab.length) == 0)
n = (tab = resize()).length;
if ((p = tab[i = (n - 1) & hash]) == null)
@@ -740,6 +802,8 @@ public class HashMap<K,V> extends AbstractMap<K,V>
}
}
}
+
+ createIntegerCache();
return newTab;
}
@@ -839,6 +903,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
p.next = node.next;
++modCount;
--size;
+
+ if (integerCache != null) {
+ updateIntegerCache(node.key, null, false);
+ }
afterNodeRemoval(node);
return node;
}
@@ -858,6 +926,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
for (int i = 0; i < tab.length; ++i)
tab[i] = null;
}
+ integerCache = null;
}
/**
@@ -882,6 +951,82 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return false;
}
+ /**
+ * 1. iterator all Keys and statistic
+ * Integer Key count, total count is size
+ * Integer Key count in range [0, table.length], get Max value.
+ *
+ * 2. Create integer cache
+ */
+ @SuppressWarnings({"unchecked"})
+ private final void createIntegerCache() {
+ int n = table.length;
+ int intKeyCount = 0;
+ int intKeyCountInrange = 0;
+ int maxIntKey = 0;
+ if (n < MIN_INTEGER_CACHE || (enableIntegerCache == false)) {
+ integerCache = null;
+ return;
+ }
+ Iterator<K> it = this.keySet().iterator();
+ while (it.hasNext()) {
+ K key = it.next();
+ if (key != null && key instanceof Integer) {
+ intKeyCount++;
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < n) {
+ intKeyCountInrange++;
+ if (val > maxIntKey)
+ maxIntKey = val;
+ }
+ }
+ }
+ float keyIntRation = ((float)intKeyCount) / size;
+ float keyIntInRangeRation = ((float)intKeyCountInrange) / size;
+ if (keyIntRation >= INTEGER_CACHE_FACTOR &&
+ keyIntInRangeRation >= INTEGER_CACHE_FACTOR) {
+ // compute integerCache size
+ int cacheMapSize = n < (2 * maxIntKey) ? n : (2 * maxIntKey);
+ integerCache = new Object[cacheMapSize];
+ Iterator<Map.Entry<K,V>> entries = this.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry<K,V> thisEntry = entries.next();
+ K key = thisEntry.getKey();
+ V value = thisEntry.getValue();
+ if (key != null && key instanceof Integer) {
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < integerCache.length) {
+ integerCache[val] = value;
+ }
+ }
+ }
+ } else {
+ integerCache = null;
+ }
+ }
+
+ /**
+ * put if integerCache null check outside of this call
+ * JIT will not inline this method (not hot) when HashMap is not Integer Key intensive.
+ * Otherwise it will always inline updateIntegerCache method.
+ *
+ */
+ private final void updateIntegerCache(K key, V value, boolean onlyIfAbsent) {
+ if (enableIntegerCache == false) {
+ integerCache = null;
+ return;
+ }
+ if (key != null && key instanceof Integer) {
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < integerCache.length) {
+ if (onlyIfAbsent && integerCache[val] != null) {
+ return;
+ }
+ integerCache[val] = value;
+ }
+ }
+ }
+
/**
* Returns a {@link Set} view of the keys contained in this map.
* The set is backed by the map, so changes to the map are
@@ -1047,7 +1192,19 @@ public class HashMap<K,V> extends AbstractMap<K,V>
// Overrides of JDK8 Map extension methods
@Override
+ @SuppressWarnings("unchecked")
public V getOrDefault(Object key, V defaultValue) {
+ if (integerCache != null) {
+ if (enableIntegerCache == false) {
+ integerCache = null;
+ } else if (key != null && key instanceof Integer) {
+ V value;
+ int val = ((Integer)key).intValue();
+ if (val >= 0 && val < integerCache.length && (value = (V)integerCache[val]) != null) {
+ return value;
+ }
+ }
+ }
Node<K,V> e;
return (e = getNode(hash(key), key)) == null ? defaultValue : e.value;
}
@@ -1068,6 +1225,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if ((e = getNode(hash(key), key)) != null &&
((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) {
e.value = newValue;
+ if (integerCache != null) {
+ updateIntegerCache(key, newValue, false);
+ }
afterNodeAccess(e);
return true;
}
@@ -1080,6 +1240,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if ((e = getNode(hash(key), key)) != null) {
V oldValue = e.value;
e.value = value;
+ if (integerCache != null) {
+ updateIntegerCache(key, value, false);
+ }
afterNodeAccess(e);
return oldValue;
}
@@ -1136,6 +1299,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return null;
} else if (old != null) {
old.value = v;
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
afterNodeAccess(old);
return v;
}
@@ -1146,6 +1312,11 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (binCount >= TREEIFY_THRESHOLD - 1)
treeifyBin(tab, hash);
}
+
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
+
modCount = mc + 1;
++size;
afterNodeInsertion(true);
@@ -1176,6 +1347,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (mc != modCount) { throw new ConcurrentModificationException(); }
if (v != null) {
e.value = v;
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
afterNodeAccess(e);
return v;
}
@@ -1230,6 +1404,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (old != null) {
if (v != null) {
old.value = v;
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
afterNodeAccess(old);
}
else
@@ -1243,6 +1420,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (binCount >= TREEIFY_THRESHOLD - 1)
treeifyBin(tab, hash);
}
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
modCount = mc + 1;
++size;
afterNodeInsertion(true);
@@ -1303,6 +1483,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
}
if (v != null) {
old.value = v;
+ if (integerCache != null) {
+ updateIntegerCache(key, v, false);
+ }
afterNodeAccess(old);
}
else
@@ -1317,6 +1500,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
if (binCount >= TREEIFY_THRESHOLD - 1)
treeifyBin(tab, hash);
}
+ if (integerCache != null) {
+ updateIntegerCache(key, value, false);
+ }
++modCount;
++size;
afterNodeInsertion(true);
@@ -1350,6 +1536,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
for (Node<K,V> e : tab) {
for (; e != null; e = e.next) {
e.value = function.apply(e.key, e.value);
+ if (integerCache != null) {
+ updateIntegerCache(e.key, e.value, false);
+ }
}
}
if (modCount != mc)
@@ -1823,6 +2012,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
modCount = 0;
threshold = 0;
size = 0;
+ integerCache = null;
}
// Callbacks to allow LinkedHashMap post-actions
diff --git a/src/java.base/share/classes/jdk/internal/misc/Unsafe.java b/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
index d78caabdc..4d71e671e 100644
--- a/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
+++ b/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
@@ -3702,7 +3702,7 @@ public final class Unsafe {
private static int convEndian(boolean big, int n) { return big == BE ? n : Integer.reverseBytes(n) ; }
private static long convEndian(boolean big, long n) { return big == BE ? n : Long.reverseBytes(n) ; }
-
+ public native boolean getUseHashMapIntegerCache();
public native boolean getUseFastSerializer();
private native long allocateMemory0(long bytes);
private native long reallocateMemory0(long address, long bytes);
--
2.19.1

View File

@ -0,0 +1,328 @@
diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp
index fa2b2ddea..b357a36cd 100644
--- a/src/hotspot/os/linux/os_linux.cpp
+++ b/src/hotspot/os/linux/os_linux.cpp
@@ -5273,7 +5273,6 @@ void os::Linux::numa_init() {
ls.print(" %d", node);
}
}
- log_info(gc, heap)("UseNUMA enabled for G1");
}
}
diff --git a/src/hotspot/share/gc/z/zDriver.cpp b/src/hotspot/share/gc/z/zDriver.cpp
index b3056bfcc..a9b905341 100644
--- a/src/hotspot/share/gc/z/zDriver.cpp
+++ b/src/hotspot/share/gc/z/zDriver.cpp
@@ -324,6 +324,17 @@ public:
}
};
+class ZDriverRelocationScopeHelper : public StackObj {
+public:
+ ZDriverRelocationScopeHelper() {
+ ZStatRelocationRate::at_start();
+ }
+
+ ~ZDriverRelocationScopeHelper() {
+ ZStatRelocationRate::at_end();
+ }
+};
+
void ZDriver::run_gc_cycle(GCCause::Cause cause) {
ZDriverCycleScope scope(cause);
@@ -381,12 +392,12 @@ void ZDriver::run_gc_cycle(GCCause::Cause cause) {
// Phase 9: Pause Relocate Start
{
+ ZDriverRelocationScopeHelper scope_helper();
ZRelocateStartClosure cl;
vm_operation(&cl);
- }
- // Phase 10: Concurrent Relocate
- {
+ // Phase 10: Concurrent Relocate
+
ZStatTimer timer(ZPhaseConcurrentRelocated);
ZHeap::heap()->relocate();
}
diff --git a/src/hotspot/share/gc/z/zRelocationSetSelector.cpp b/src/hotspot/share/gc/z/zRelocationSetSelector.cpp
index 222529f14..780415498 100644
--- a/src/hotspot/share/gc/z/zRelocationSetSelector.cpp
+++ b/src/hotspot/share/gc/z/zRelocationSetSelector.cpp
@@ -26,27 +26,52 @@
#include "gc/z/zPage.inline.hpp"
#include "gc/z/zRelocationSet.hpp"
#include "gc/z/zRelocationSetSelector.hpp"
+#include "gc/z/zStat.hpp"
#include "logging/log.hpp"
#include "runtime/globals.hpp"
#include "utilities/debug.hpp"
+// means the probability is 1 in 1000 that a sample is outside of the confidence interval.
+const double ZRelocationSetSelectorGroup::one_in_1000 = 3.290527;
+
ZRelocationSetSelectorGroup::ZRelocationSetSelectorGroup(const char* name,
size_t page_size,
size_t object_size_limit) :
_name(name),
_page_size(page_size),
_object_size_limit(object_size_limit),
- _fragmentation_limit(page_size * (ZFragmentationLimit / 100)),
+ _fragmentation_limit(ZAdatpivePageRelcaim ? (page_size * (ZPageMinWastePercent / 100)) :
+ (page_size * (ZFragmentationLimit / 100))),
+ _predication_relocation_size(0),
_registered_pages(),
_sorted_pages(NULL),
_nselected(0),
_relocating(0),
- _fragmentation(0) {}
+ _fragmentation(0) {
+ if (is_fragment_limit_adatpive() && page_size == ZPageSizeSmall) {
+ // Predicate the relocation rate
+ double max_relocation_rate = 0.0;
+ max_relocation_rate = (ZStatRelocationRate::small_avg() * ZAllocationSpikeTolerance) +
+ (ZStatRelocationRate::small_avg_sd() * one_in_1000);
+
+ // The decay average time
+ const AbsSeq& duration_of_relocation = ZStatRelocationRate::duration();
+ const double max_duration_of_relocation =
+ duration_of_relocation.davg() + (duration_of_relocation.dsd() * one_in_1000);
+
+ _predication_relocation_size = (size_t)max_relocation_rate * max_duration_of_relocation;
+ log_info(gc, reloc)("Predication Relocation size: " SIZE_FORMAT, _predication_relocation_size);
+ }
+}
ZRelocationSetSelectorGroup::~ZRelocationSetSelectorGroup() {
FREE_C_HEAP_ARRAY(const ZPage*, _sorted_pages);
}
+bool ZRelocationSetSelectorGroup::is_fragment_limit_adatpive() {
+ return ZAdatpivePageRelcaim && ZStatCycle::ncycles() >= 3; // warm up needs 2 cycles
+}
+
void ZRelocationSetSelectorGroup::register_live_page(const ZPage* page, size_t garbage) {
if (garbage > _fragmentation_limit) {
_registered_pages.add(page);
@@ -104,12 +129,25 @@ void ZRelocationSetSelectorGroup::select() {
size_t selected_from = 0;
size_t selected_to = 0;
size_t from_size = 0;
+ bool is_abortable_selection = false;
+ size_t cur_page_live_bytes = 0;
+ double page_min_live_percent = 100 - ZPageMaxWastePercent;
semi_sort();
for (size_t from = 1; from <= npages; from++) {
// Add page to the candidate relocation set
- from_size += _sorted_pages[from - 1]->live_bytes();
+ cur_page_live_bytes = _sorted_pages[from - 1]->live_bytes();
+ from_size += cur_page_live_bytes;
+ // Abortable selection for relocation
+ if (is_fragment_limit_adatpive() && _page_size == ZPageSizeSmall &&
+ from_size >= _predication_relocation_size &&
+ percent_of(cur_page_live_bytes, ZPageSizeSmall) > page_min_live_percent) {
+ // Get really relocation bytes
+ from_size -= cur_page_live_bytes;
+ is_abortable_selection = true;
+ break;
+ }
// Calculate the maximum number of pages needed by the candidate relocation set.
// By subtracting the object size limit from the pages size we get the maximum
@@ -130,8 +168,13 @@ void ZRelocationSetSelectorGroup::select() {
}
log_trace(gc, reloc)("Candidate Relocation Set (%s Pages): "
- SIZE_FORMAT "->" SIZE_FORMAT ", %.1f%% relative defragmentation, %s",
- _name, from, to, diff_reclaimable, (selected_from == from) ? "Selected" : "Rejected");
+ SIZE_FORMAT "->" SIZE_FORMAT ", %.1f%% relative defragmentation, %s",
+ _name, from, to, diff_reclaimable, (selected_from == from) ? "Selected" : "Rejected");
+ }
+
+ if (is_abortable_selection) {
+ log_info(gc, reloc)("Abortable selection for Small Page really relocation byte is: " SIZE_FORMAT
+ ", predication relocation byte is: " SIZE_FORMAT, from_size, _predication_relocation_size);
}
// Finalize selection
@@ -146,6 +189,22 @@ void ZRelocationSetSelectorGroup::select() {
log_debug(gc, reloc)("Relocation Set (%s Pages): " SIZE_FORMAT "->" SIZE_FORMAT ", " SIZE_FORMAT " skipped",
_name, selected_from, selected_to, npages - _nselected);
+
+ calculate_live_bytes();
+}
+
+void ZRelocationSetSelectorGroup::calculate_live_bytes() {
+ if (_page_size != ZPageSizeSmall) {
+ return;
+ }
+
+ if ((!ZAdatpivePageRelcaim) && (ZStatCycle::ncycles() >= 3)) {
+ return;
+ }
+
+ for (size_t from = 0; from < _nselected; from++) {
+ ZStatRelocation::_small_page_live_bytes += _sorted_pages[from]->live_bytes();
+ }
}
const ZPage* const* ZRelocationSetSelectorGroup::selected() const {
diff --git a/src/hotspot/share/gc/z/zRelocationSetSelector.hpp b/src/hotspot/share/gc/z/zRelocationSetSelector.hpp
index 1aa1142d5..92d2a6f39 100644
--- a/src/hotspot/share/gc/z/zRelocationSetSelector.hpp
+++ b/src/hotspot/share/gc/z/zRelocationSetSelector.hpp
@@ -32,10 +32,13 @@ class ZRelocationSet;
class ZRelocationSetSelectorGroup {
private:
+ static const double one_in_1000;
+
const char* const _name;
const size_t _page_size;
const size_t _object_size_limit;
const size_t _fragmentation_limit;
+ size_t _predication_relocation_size;
ZArray<const ZPage*> _registered_pages;
const ZPage** _sorted_pages;
@@ -43,6 +46,7 @@ private:
size_t _relocating;
size_t _fragmentation;
+ bool is_fragment_limit_adatpive();
void semi_sort();
public:
@@ -53,6 +57,7 @@ public:
void register_live_page(const ZPage* page, size_t garbage);
void select();
+ void calculate_live_bytes();
const ZPage* const* selected() const;
size_t nselected() const;
diff --git a/src/hotspot/share/gc/z/zStat.cpp b/src/hotspot/share/gc/z/zStat.cpp
index 3b55bdadd..a586e2897 100644
--- a/src/hotspot/share/gc/z/zStat.cpp
+++ b/src/hotspot/share/gc/z/zStat.cpp
@@ -1101,6 +1101,7 @@ void ZStatMark::print() {
// Stat relocation
//
size_t ZStatRelocation::_relocating;
+size_t ZStatRelocation::_small_page_live_bytes;
bool ZStatRelocation::_success;
void ZStatRelocation::set_at_select_relocation_set(size_t relocating) {
@@ -1119,6 +1120,42 @@ void ZStatRelocation::print() {
}
}
+//
+// Stat relcoation rate
+//
+Ticks ZStatRelocationRate::_start_of_last;
+Ticks ZStatRelocationRate::_end_of_last;
+NumberSeq ZStatRelocationRate::_duration(0.3 /* alpha */);
+TruncatedSeq ZStatRelocationRate::_small_rate;
+TruncatedSeq ZStatRelocationRate::_small_rate_avg;
+
+void ZStatRelocationRate::at_start() {
+ _start_of_last = Ticks::now();
+}
+
+void ZStatRelocationRate::at_end() {
+ _end_of_last = Ticks::now();
+
+ const double duration = (_end_of_last - _start_of_last).seconds() + 1.0; // Add 1.0 to avoid the duration close zero
+ _duration.add(duration);
+
+ const double small_bytes_per_second = ZStatRelocation::_small_page_live_bytes / duration;
+ _small_rate.add(small_bytes_per_second);
+ _small_rate_avg.add(_small_rate.avg());
+}
+
+const AbsSeq& ZStatRelocationRate::duration() {
+ return _duration;
+}
+
+double ZStatRelocationRate::small_avg() {
+ return _small_rate.avg();
+}
+
+double ZStatRelocationRate::small_avg_sd() {
+ return _small_rate_avg.sd();
+}
+
//
// Stat nmethods
//
diff --git a/src/hotspot/share/gc/z/zStat.hpp b/src/hotspot/share/gc/z/zStat.hpp
index 3390466e6..f826378f3 100644
--- a/src/hotspot/share/gc/z/zStat.hpp
+++ b/src/hotspot/share/gc/z/zStat.hpp
@@ -392,12 +392,33 @@ private:
static bool _success;
public:
+ static size_t _small_page_live_bytes;
static void set_at_select_relocation_set(size_t relocating);
static void set_at_relocate_end(bool success);
-
static void print();
};
+//
+// Stat relocation rate
+//
+class ZStatRelocationRate : public AllStatic {
+private:
+ static Ticks _start_of_last;
+ static Ticks _end_of_last;
+ static NumberSeq _duration;
+ static TruncatedSeq _small_rate; // B/s
+ static TruncatedSeq _small_rate_avg; // B/s
+
+public:
+ static void at_start();
+ static void at_end();
+
+ static const AbsSeq& duration();
+
+ static double small_avg();
+ static double small_avg_sd();
+};
+
//
// Stat nmethods
//
diff --git a/src/hotspot/share/gc/z/z_globals.hpp b/src/hotspot/share/gc/z/z_globals.hpp
index 8cee59be7..326e8ec40 100644
--- a/src/hotspot/share/gc/z/z_globals.hpp
+++ b/src/hotspot/share/gc/z/z_globals.hpp
@@ -49,6 +49,17 @@
product(double, ZFragmentationLimit, 25.0, \
"Maximum allowed heap fragmentation") \
\
+ experimental(bool, ZAdatpivePageRelcaim, false, \
+ "Adapptive page relcaim at relcoation phase") \
+ \
+ develop(double, ZPageMinWastePercent, 5.0, \
+ "Amount of space, expressed as a percentage of the page size, " \
+ "that ZGC is willing not to collect to avoid expensive GCs.") \
+ range(0.0, 100.0) \
+ \
+ product(double, ZPageMaxWastePercent, 30.0, "Adaptive small page " \
+ "seclect minmum pages percent.")range(0.0, 100.0) \
+ \
product(bool, ZStallOnOutOfMemory, true, \
"Allow Java threads to stall and wait for GC to complete " \
"instead of immediately throwing an OutOfMemoryError") \
--
2.19.1

View File

@ -735,7 +735,7 @@ Provides: java-src%{?1} = %{epoch}:%{version}-%{release}
Name: java-%{javaver}-%{origin}
Version: %{newjavaver}.%{buildver}
Release: 4
Release: 10
# java-1.5.0-ibm from jpackage.org set Epoch to 1 for unknown reasons
# and this change was brought into RHEL-4. java-1.5.0-ibm packages
# also included the epoch in their virtual provides. This created a
@ -836,7 +836,13 @@ Patch50: 8248336-AArch64-C2-offset-overflow-in-BoxLockNode-em.patch
# 11.0.9
Patch51: 8255781-Bump-patch-update-version-for-OpenJDK-jdk-11.0.9.1.patch
Patch52: 8250861-Crash-in-MinINode-Ideal.patch
Patch53: 8236512-PKCS11-Connection-closed-after-Cipher-doFinal-and-NoPadding.patch
Patch54: 8207160-ClassReader-adjustMethodParams-can-potentially-return-null-if-the-args-list-is-empty.patch
Patch55: 8215047-Task-terminators-do-not-complete-termination-in-consistent-state.patch
Patch56: 8247766-aarch64-guarantee-val-1U--nbits-failed-Field-too-big-for-insn.patch
Patch57: add-zgc-parameter-adaptation-feature.patch
Patch58: add-integerCache-feature.patch
Patch59: add-SVE-backend-feature.patch
BuildRequires: autoconf
BuildRequires: alsa-lib-devel
@ -1102,6 +1108,13 @@ pushd %{top_level_dir_name}
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
%patch55 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
popd # openjdk
%patch1000
@ -1604,6 +1617,25 @@ require "copy_jdk_configs.lua"
%changelog
* Thu Dec 24 2020 kuenking <wangkun49@huawei.com> - 1:11.0.9.11-10
- add add-SVE-backend-feature.patch
* Thu Dec 24 2020 kuenking <wangkun49@huawei.com> - 1:11.0.9.11-9
- add add-integerCache-feature.patch
* Thu Dec 24 2020 kuenking <wangkun49@huawei.com> - 1:11.0.9.11-8
- add add-zgc-parameter-adaptation-feature.patch
* Wed Dec 23 2020 alapha <sunjianye@huawei.com> - 1:11.0.9.11-7
- add 8215047-Task-terminators-do-not-complete-termination-in-consistent-state.patch
- add 8247766-aarch64-guarantee-val-1U--nbits-failed-Field-too-big-for-insn.patch
* Wed Dec 23 2020 eapen <zhangyipeng7@huawei.com> - 1:11.0.9.11-6
- add 8207160-ClassReader-adjustMethodParams-can-potentially-return-null-if-the-args-list-is-empty.patch
* Tue Dec 22 2020 aijm <aijiaming1@huawei.com> - 1:11.0.9.11-5
- add 8236512-PKCS11-Connection-closed-after-Cipher-doFinal-and-NoPadding.patch
* Mon Dec 21 2020 noah <hedongbo@huawei.com> - 1:11.0.9.11-4
- add a license to this repo