Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_check/CheckVMThreadStacks.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2014 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
#include "CheckEngine.hpp"
24
#include "CheckVMThreadStacks.hpp"
25
#include "ModronTypes.hpp"
26
#include "ScanFormatter.hpp"
27
28
/**
29
* Wrapper for GC_CheckEngine::checkSlot being used by GC_VMThreadStackSlotIterator::scanSlots
30
*
31
* @param objectIndirect the slot to be verified
32
* @param localData the same value that was passed to GC_VMThreadStackSlotIterator::scanSlots
33
* in the <code>userData</code> parameter
34
* @param isDerivedPointer legacy - not used
35
* @param objectIndirectBase the object that contains the slot
36
*
37
* @see GC_VMThreadStackSlotIterator::scanSlots
38
*/
39
void
40
checkStackSlotIterator(J9JavaVM *javaVM, J9Object **objectIndirect, void *localData, J9StackWalkState *walkState, const void *stackLocation)
41
{
42
GC_CheckVMThreadStacks::checkStackIteratorData *checkStackIteratorData = (GC_CheckVMThreadStacks::checkStackIteratorData *)localData;
43
44
if (J9MODRON_SLOT_ITERATOR_RECOVERABLE_ERROR == checkStackIteratorData->gcCheck->checkSlotStack(checkStackIteratorData->gcCheck->getJavaVM(), objectIndirect, checkStackIteratorData->walkThread, stackLocation)) {
45
checkStackIteratorData->numberOfErrors += 1;
46
}
47
}
48
49
/**
50
* Wrapper for GC_CheckEngine::checkSlot being used by GC_VMThreadStackSlotIterator::scanSlots
51
*
52
* @param objectIndirect the slot to be printed
53
* @param localData the same value that was passed to GC_VMThreadStackSlotIterator::scanSlots
54
* in the <code>userData</code> parameter
55
* @param isDerivedPointer legacy - not used
56
* @param objectIndirectBase the object that contains the slot
57
*
58
* @see GC_VMThreadStackSlotIterator::scanSlots
59
*/
60
void
61
printStackSlotIterator(J9JavaVM *javaVM, J9Object **objectIndirect, void *localData, J9StackWalkState *walkState, const void *stackLocation)
62
{
63
GC_CheckVMThreadStacks::printStackIteratorData *printStackIteratorData = (GC_CheckVMThreadStacks::printStackIteratorData *)localData;
64
65
printStackIteratorData->scanFormatter->entry((void *) *objectIndirect);
66
}
67
68
GC_Check *
69
GC_CheckVMThreadStacks::newInstance(J9JavaVM *javaVM, GC_CheckEngine *engine)
70
{
71
MM_Forge *forge = MM_GCExtensions::getExtensions(javaVM)->getForge();
72
73
GC_CheckVMThreadStacks *check = (GC_CheckVMThreadStacks *) forge->allocate(sizeof(GC_CheckVMThreadStacks), MM_AllocationCategory::DIAGNOSTIC, J9_GET_CALLSITE());
74
if(check) {
75
new(check) GC_CheckVMThreadStacks(javaVM, engine);
76
}
77
return check;
78
}
79
80
void
81
GC_CheckVMThreadStacks::kill()
82
{
83
MM_Forge *forge = MM_GCExtensions::getExtensions(_javaVM)->getForge();
84
forge->free(this);
85
}
86
87
void
88
GC_CheckVMThreadStacks::check()
89
{
90
GC_VMThreadListIterator vmThreadListIterator(_javaVM);
91
J9VMThread *walkThread;
92
#if defined(J9VM_INTERP_VERBOSE)
93
bool doStackDump = _engine->isStackDumpAlwaysDisplayed();
94
#endif /* J9VM_INTERP_VERBOSE */
95
96
while((walkThread = vmThreadListIterator.nextVMThread()) != NULL) {
97
J9VMThread *toScanWalkThread;
98
checkStackIteratorData localData = { _engine, walkThread, 0 };
99
toScanWalkThread = walkThread;
100
if (NULL != toScanWalkThread) {
101
GC_VMThreadStackSlotIterator::scanSlots(toScanWalkThread, toScanWalkThread, (void *)&localData, checkStackSlotIterator, false, false);
102
103
#if defined(J9VM_INTERP_VERBOSE)
104
if (_javaVM->verboseStackDump && (doStackDump || (localData.numberOfErrors > 0))) {
105
_javaVM->verboseStackDump(toScanWalkThread, "bad object detected on stack");
106
}
107
#endif /* J9VM_INTERP_VERBOSE */
108
}
109
}
110
}
111
112
void
113
GC_CheckVMThreadStacks::print()
114
{
115
GC_VMThreadListIterator newVMThreadListIterator(_javaVM);
116
J9VMThread *walkThread;
117
118
/* call into the VM to print slots and stacks for each thread. */
119
GC_ScanFormatter formatter(_portLibrary, "thread stacks");
120
while((walkThread = newVMThreadListIterator.nextVMThread()) != NULL) {
121
122
/* first we print the stack slots */
123
formatter.section("thread slots", (void *) walkThread);
124
J9VMThread *toScanWalkThread;
125
printStackIteratorData localData = { &formatter, walkThread};
126
toScanWalkThread = walkThread;
127
GC_VMThreadStackSlotIterator::scanSlots(toScanWalkThread, toScanWalkThread, (void *)&localData, printStackSlotIterator, false, false);
128
formatter.endSection();
129
130
/* then we print the stack trace itself */
131
formatter.section("thread stack", (void *) walkThread);
132
_javaVM->internalVMFunctions->dumpStackTrace(walkThread);
133
formatter.endSection();
134
}
135
formatter.end("thread stacks");
136
}
137
138
139