changeset 49209:1817d118ff66

8198267: Allow GCId::current_raw() calls from non-NamedThreads Reviewed-by: stefank, kbarrett
author pliden
date Wed, 21 Feb 2018 07:46:40 +0100
parents 010df2533db2
children e4a0cc16b050
files src/hotspot/share/gc/g1/g1PageBasedVirtualSpace.cpp src/hotspot/share/gc/shared/gcId.cpp src/hotspot/share/gc/shared/gcId.hpp src/hotspot/share/gc/shared/workgroup.hpp test/hotspot/gtest/gc/shared/test_oopStorage.cpp
diffstat 5 files changed, 19 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/g1/g1PageBasedVirtualSpace.cpp	Tue Feb 20 16:18:25 2018 -0600
+++ b/src/hotspot/share/gc/g1/g1PageBasedVirtualSpace.cpp	Wed Feb 21 07:46:40 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -235,13 +235,7 @@
   size_t const _page_size;
 public:
   G1PretouchTask(char* start_address, char* end_address, size_t page_size) :
-    AbstractGangTask("G1 PreTouch",
-                     Universe::is_fully_initialized() &&
-                     Thread::current()->is_Named_thread() ? GCId::current_raw() :
-                                                            // During VM initialization there is
-                                                            // no GC cycle that this task can be
-                                                            // associated with.
-                                                            GCId::undefined()),
+    AbstractGangTask("G1 PreTouch"),
     _cur_addr(start_address),
     _start_addr(start_address),
     _end_addr(end_address),
--- a/src/hotspot/share/gc/shared/gcId.cpp	Tue Feb 20 16:18:25 2018 -0600
+++ b/src/hotspot/share/gc/shared/gcId.cpp	Wed Feb 21 07:46:40 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -44,18 +44,19 @@
 }
 
 const uint GCId::current() {
-  assert(currentNamedthread()->gc_id() != undefined(), "Using undefined GC id.");
-  return current_raw();
+  const uint gc_id = currentNamedthread()->gc_id();
+  assert(gc_id != undefined(), "Using undefined GC id.");
+  return gc_id;
 }
 
-const uint GCId::current_raw() {
-  return currentNamedthread()->gc_id();
+const uint GCId::current_or_undefined() {
+  return Thread::current()->is_Named_thread() ? currentNamedthread()->gc_id() : undefined();
 }
 
 size_t GCId::print_prefix(char* buf, size_t len) {
   Thread* thread = Thread::current_or_null();
-  if (thread != NULL && thread->is_Named_thread()) {
-    uint gc_id = current_raw();
+  if (thread != NULL) {
+    uint gc_id = current_or_undefined();
     if (gc_id != undefined()) {
       int ret = jio_snprintf(buf, len, "GC(%u) ", gc_id);
       assert(ret > 0, "Failed to print prefix. Log buffer too small?");
@@ -78,12 +79,12 @@
 }
 
 GCIdMarkAndRestore::GCIdMarkAndRestore() : _gc_id(GCId::create()) {
-  _previous_gc_id = GCId::current_raw();
+  _previous_gc_id = currentNamedthread()->gc_id();
   currentNamedthread()->set_gc_id(_gc_id);
 }
 
 GCIdMarkAndRestore::GCIdMarkAndRestore(uint gc_id) : _gc_id(gc_id) {
-  _previous_gc_id = GCId::current_raw();
+  _previous_gc_id = currentNamedthread()->gc_id();
   currentNamedthread()->set_gc_id(_gc_id);
 }
 
--- a/src/hotspot/share/gc/shared/gcId.hpp	Tue Feb 20 16:18:25 2018 -0600
+++ b/src/hotspot/share/gc/shared/gcId.hpp	Wed Feb 21 07:46:40 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -38,7 +38,7 @@
   // Returns the currently active GC id. Asserts that there is an active GC id.
   static const uint current();
   // Same as current() but can return undefined() if no GC id is currently active
-  static const uint current_raw();
+  static const uint current_or_undefined();
   // Returns the next expected GCId.
   static const uint peek();
   static const uint undefined() { return UNDEFINED; }
--- a/src/hotspot/share/gc/shared/workgroup.hpp	Tue Feb 20 16:18:25 2018 -0600
+++ b/src/hotspot/share/gc/shared/workgroup.hpp	Wed Feb 21 07:46:40 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -59,14 +59,9 @@
   const uint _gc_id;
 
  public:
-  AbstractGangTask(const char* name) :
+  explicit AbstractGangTask(const char* name) :
     _name(name),
-    _gc_id(GCId::current_raw())
-  {}
-
-  AbstractGangTask(const char* name, const uint gc_id) :
-    _name(name),
-    _gc_id(gc_id)
+    _gc_id(GCId::current_or_undefined())
   {}
 
   // The abstract work method.
--- a/test/hotspot/gtest/gc/shared/test_oopStorage.cpp	Tue Feb 20 16:18:25 2018 -0600
+++ b/test/hotspot/gtest/gc/shared/test_oopStorage.cpp	Wed Feb 21 07:46:40 2018 +0100
@@ -896,7 +896,7 @@
 
 public:
   Task(const char* name, Storage* storage, VerifyState* vstate) :
-    AbstractGangTask(name, GCId::undefined()),
+    AbstractGangTask(name),
     _state(storage),
     _vstate(vstate)
   {}
@@ -915,7 +915,7 @@
 class OopStorageTestParIteration::TaskUsingOopsDo : public AbstractGangTask {
 public:
   TaskUsingOopsDo(const char* name, OopStorage* storage, VerifyState* vstate) :
-    AbstractGangTask(name, GCId::undefined()),
+    AbstractGangTask(name),
     _state(storage),
     _vstate(vstate)
   {}