src/hotspot/share/interpreter/templateInterpreter.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47916 bdbef8638948
child 58679 9c3209ff7550
--- a/src/hotspot/share/interpreter/templateInterpreter.cpp	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/hotspot/share/interpreter/templateInterpreter.cpp	Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -29,8 +29,11 @@
 #include "interpreter/templateInterpreter.hpp"
 #include "interpreter/templateInterpreterGenerator.hpp"
 #include "interpreter/templateTable.hpp"
+#include "logging/log.hpp"
 #include "memory/resourceArea.hpp"
+#include "runtime/safepoint.hpp"
 #include "runtime/timerTrace.hpp"
+#include "utilities/copy.hpp"
 
 #ifndef CC_INTERP
 
@@ -274,18 +277,28 @@
 
 
 //------------------------------------------------------------------------------------------------------------------------
-// Safepoint suppport
+// Safepoint support
 
 static inline void copy_table(address* from, address* to, int size) {
-  // Copy non-overlapping tables. The copy has to occur word wise for MT safety.
-  while (size-- > 0) *to++ = *from++;
+  // Copy non-overlapping tables.
+  if (SafepointSynchronize::is_at_safepoint()) {
+    // Nothing is using the table at a safepoint so skip atomic word copy.
+    Copy::disjoint_words((HeapWord*)from, (HeapWord*)to, (size_t)size);
+  } else {
+    // Use atomic word copy when not at a safepoint for safety.
+    Copy::disjoint_words_atomic((HeapWord*)from, (HeapWord*)to, (size_t)size);
+  }
 }
 
 void TemplateInterpreter::notice_safepoints() {
   if (!_notice_safepoints) {
+    log_debug(interpreter, safepoint)("switching active_table to safept_table.");
     // switch to safepoint dispatch table
     _notice_safepoints = true;
     copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
+  } else {
+    log_debug(interpreter, safepoint)("active_table is already safept_table; "
+                                      "notice_safepoints() call is no-op.");
   }
 }
 
@@ -297,10 +310,17 @@
 void TemplateInterpreter::ignore_safepoints() {
   if (_notice_safepoints) {
     if (!JvmtiExport::should_post_single_step()) {
+      log_debug(interpreter, safepoint)("switching active_table to normal_table.");
       // switch to normal dispatch table
       _notice_safepoints = false;
       copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
+    } else {
+      log_debug(interpreter, safepoint)("single stepping is still active; "
+                                        "ignoring ignore_safepoints() call.");
     }
+  } else {
+    log_debug(interpreter, safepoint)("active_table is already normal_table; "
+                                      "ignore_safepoints() call is no-op.");
   }
 }