Thu, 08 Feb 2018 00:23:31 +0000
8187577: JVM crash during gc doing concurrent marking
Summary: Inform G1's SATB that a klass has been resurrected and it should not be unloaded
Reviewed-by: coleenp, tschatzl, kbarrett
src/share/vm/prims/jvmtiGetLoadedClasses.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/prims/jvmtiGetLoadedClasses.cpp Wed Feb 07 09:44:08 2018 -0800 1.2 +++ b/src/share/vm/prims/jvmtiGetLoadedClasses.cpp Thu Feb 08 00:23:31 2018 +0000 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -27,6 +27,9 @@ 1.11 #include "memory/universe.inline.hpp" 1.12 #include "prims/jvmtiGetLoadedClasses.hpp" 1.13 #include "runtime/thread.hpp" 1.14 +#if INCLUDE_ALL_GCS 1.15 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 1.16 +#endif 1.17 1.18 1.19 // The closure for GetLoadedClasses 1.20 @@ -35,6 +38,20 @@ 1.21 Stack<jclass, mtInternal> _classStack; 1.22 JvmtiEnv* _env; 1.23 1.24 +// Tell the GC to keep this klass alive 1.25 +static void ensure_klass_alive(oop o) { 1.26 + // A klass that was previously considered dead can be looked up in the 1.27 + // CLD/SD, and its _java_mirror or _class_loader can be stored in a root 1.28 + // or a reachable object making it alive again. The SATB part of G1 needs 1.29 + // to get notified about this potential resurrection, otherwise the marking 1.30 + // might not find the object. 1.31 +#if INCLUDE_ALL_GCS 1.32 + if (UseG1GC && o != NULL) { 1.33 + G1SATBCardTableModRefBS::enqueue(o); 1.34 + } 1.35 +#endif 1.36 +} 1.37 + 1.38 public: 1.39 LoadedClassesClosure(JvmtiEnv* env) { 1.40 _env = env; 1.41 @@ -43,6 +60,7 @@ 1.42 void do_klass(Klass* k) { 1.43 // Collect all jclasses 1.44 _classStack.push((jclass) _env->jni_reference(k->java_mirror())); 1.45 + ensure_klass_alive(k->java_mirror()); 1.46 } 1.47 1.48 int extract(jclass* result_list) {