5ea879a
# HG changeset patch
5ea879a
# User poonam
5ea879a
# Date 1525279722 -3600
5ea879a
#      Wed May 02 17:48:42 2018 +0100
5ea879a
# Node ID ffd5260fe5adcb26f87a14f1aaaf3e1a075d712a
5ea879a
# Parent  5460c427c0dcb335f510cbc2ea1d76c6921b1aaa
5ea879a
8187577, PR3578: JVM crash during gc doing concurrent marking
5ea879a
Summary: Inform G1's SATB that a klass has been resurrected and it should not be unloaded
5ea879a
Reviewed-by: coleenp, tschatzl, kbarrett
5ea879a
5ea879a
diff --git openjdk.orig/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp openjdk/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp
5ea879a
--- openjdk.orig/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp
5ea879a
+++ openjdk/hotspot/src/share/vm/prims/jvmtiGetLoadedClasses.cpp
5ea879a
@@ -1,5 +1,5 @@
5ea879a
 /*
5ea879a
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
5ea879a
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
5ea879a
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ea879a
  *
5ea879a
  * This code is free software; you can redistribute it and/or modify it
5ea879a
@@ -27,6 +27,9 @@
5ea879a
 #include "memory/universe.inline.hpp"
5ea879a
 #include "prims/jvmtiGetLoadedClasses.hpp"
5ea879a
 #include "runtime/thread.hpp"
5ea879a
+#if INCLUDE_ALL_GCS
5ea879a
+#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
5ea879a
+#endif
5ea879a
 
5ea879a
 
5ea879a
 // The closure for GetLoadedClasses
5ea879a
@@ -35,6 +38,20 @@
5ea879a
   Stack<jclass, mtInternal> _classStack;
5ea879a
   JvmtiEnv* _env;
5ea879a
 
5ea879a
+// Tell the GC to keep this klass alive
5ea879a
+static void ensure_klass_alive(oop o) {
5ea879a
+  // A klass that was previously considered dead can be looked up in the
5ea879a
+  // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
5ea879a
+  // or a reachable object making it alive again. The SATB part of G1 needs
5ea879a
+  // to get notified about this potential resurrection, otherwise the marking
5ea879a
+  // might not find the object.
5ea879a
+#if INCLUDE_ALL_GCS
5ea879a
+  if (UseG1GC && o != NULL) {
5ea879a
+    G1SATBCardTableModRefBS::enqueue(o);
5ea879a
+  }
5ea879a
+#endif
5ea879a
+}
5ea879a
+
5ea879a
 public:
5ea879a
   LoadedClassesClosure(JvmtiEnv* env) {
5ea879a
     _env = env;
5ea879a
@@ -43,6 +60,7 @@
5ea879a
   void do_klass(Klass* k) {
5ea879a
     // Collect all jclasses
5ea879a
     _classStack.push((jclass) _env->jni_reference(k->java_mirror()));
5ea879a
+    ensure_klass_alive(k->java_mirror());
5ea879a
   }
5ea879a
 
5ea879a
   int extract(jclass* result_list) {