Skip to content

Commit 6047e30

Browse files
committed
Bug 37117835 - dbghelp based backtrace support on Windows has memory overhead of 80-200MB
[git-p4: depot-paths = "//dev/main.cpp/": change = 111774]
1 parent 806129a commit 6047e30

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

include/private/coherence/native/glibc/GlibcBacktrace.hpp

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
#ifndef COH_GLIBC_BACKTRACE_HPP
88
#define COH_GLIBC_BACKTRACE_HPP
@@ -14,6 +14,7 @@
1414
#include "private/coherence/native/NativeBacktrace.hpp"
1515
#include "private/coherence/native/NativeABI.hpp"
1616
#include "private/coherence/native/NativeStackElement.hpp"
17+
1718
#include "private/coherence/util/StringHelper.hpp"
1819

1920
#ifndef __USE_GNU
@@ -34,7 +35,6 @@ COH_OPEN_NAMESPACE2(coherence,native)
3435
using coherence::util::ArrayList;
3536
using coherence::util::StringHelper;
3637

37-
3838
// ----- file local helpers -------------------------------------------------
3939

4040
namespace
@@ -52,49 +52,56 @@ namespace
5252

5353
ObjectArray::Handle NativeBacktrace::getStackTrace(size32_t cTrim)
5454
{
55-
static bool fTrim = Boolean::parse(System::getProperty
56-
("coherence.threaddump.trim", "true")); // for diagnostics
55+
// COH-31048 - more relevant for Windows, but include support here as well
56+
static bool fEnabled = Boolean::parse(System::getProperty
57+
("coherence.backtrace.enabled", "true"));
5758

58-
ArrayList::Handle haFrames = ArrayList::create();
59-
String::View vsThreadRun = getThreadRun();
60-
void *frames[100];
61-
int size;
62-
63-
size = backtrace(frames, 100);
64-
cTrim += 1;
59+
static bool fTrim = Boolean::parse(System::getProperty
60+
("coherence.threaddump.trim", "true")); // for diagnostics
6561

66-
for (int i = 0, c = size - 1; i < c; i++)
62+
ArrayList::Handle haFrames = ArrayList::create();
63+
if (fEnabled)
6764
{
68-
if (fTrim && cTrim)
69-
{
70-
--cTrim;
71-
}
72-
else
73-
{
74-
void *pc = frames[i];
65+
String::View vsThreadRun = getThreadRun();
66+
void *frames[100];
67+
int size;
7568

76-
Dl_info info;
69+
size = backtrace(frames, 100);
70+
cTrim += 1;
7771

78-
if (dladdr(pc, &info) == 0)
72+
for (int i = 0, c = size - 1; i < c; i++)
73+
{
74+
if (fTrim && cTrim)
7975
{
80-
break;
76+
--cTrim;
77+
}
78+
else
79+
{
80+
void *pc = frames[i];
81+
82+
Dl_info info;
83+
84+
if (dladdr(pc, &info) == 0)
85+
{
86+
break;
87+
}
88+
89+
String::View vsName = (info.dli_sname
90+
? NativeABI::demangle(info.dli_sname)
91+
: (String::View) StringHelper::getEmptyString());
92+
93+
haFrames->add(NativeStackElement::create(
94+
(info.dli_fname
95+
? String::create(info.dli_fname)
96+
: StringHelper::getEmptyString()),
97+
vsName));
98+
99+
// trim off OS specific bits below coherence created threads
100+
if (fTrim && vsName->endsWith(vsThreadRun))
101+
{
102+
break;
103+
}
81104
}
82-
83-
String::View vsName = (info.dli_sname
84-
? NativeABI::demangle(info.dli_sname)
85-
: (String::View) StringHelper::getEmptyString());
86-
87-
haFrames->add(NativeStackElement::create(
88-
(info.dli_fname
89-
? String::create(info.dli_fname)
90-
: StringHelper::getEmptyString()),
91-
vsName));
92-
93-
// trim off OS specific bits below coherence created threads
94-
if (fTrim && vsName->endsWith(vsThreadRun))
95-
{
96-
break;
97-
}
98105
}
99106
}
100107

include/private/coherence/native/windows/WindowsBacktrace.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
#ifndef COH_WINDOWS_BACKTRACE_HPP
88
#define COH_WINDOWS_BACKTRACE_HPP
@@ -44,15 +44,25 @@ namespace
4444
*/
4545
void initializeBacktrace()
4646
{
47+
// COH-31048 - dbghelp symbol support uses a fair amount of memory; backtrace collection
48+
// can be disabled for environments where system memory is at a premium
49+
bool fBackTrace = Boolean::parse(System::getProperty("coherence.backtrace.enabled", "true"));
50+
51+
if (!fBackTrace)
52+
{
53+
fBacktraceEnabled = FALSE;
54+
return;
55+
}
56+
4757
hKernel32Dll = LoadLibrary(TEXT("kernel32.dll"));
4858
if (hKernel32Dll != NULL)
4959
{
5060
pRtlCaptureContext = (RTLCAPTURECONTEXT) GetProcAddress(hKernel32Dll, TEXT("RtlCaptureContext"));
5161

5262
if (pRtlCaptureContext != NULL)
53-
{
54-
fBacktraceEnabled = TRUE;
55-
}
63+
{
64+
fBacktraceEnabled = TRUE;
65+
}
5666
}
5767

5868
if (!fBacktraceEnabled)
@@ -78,8 +88,8 @@ namespace
7888
{
7989
// stupid function wants a char* not const char*, can't trust
8090
// that it won't modify the string
81-
size32_t cch = vsPath->getOctets()->length;
82-
char* achPath = new char[cch];
91+
size32_t cch = vsPath->getOctets()->length;
92+
char* achPath = new char[cch];
8393
strncpy_s(achPath, cch, vsPath->getCString(), cch);
8494
SymInitialize(GetCurrentProcess(), achPath, TRUE);
8595
delete[] achPath;

0 commit comments

Comments
 (0)