Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [release/8.0] JIT: Initialize jitstdout lazily by jakobbotsch · Pull Request #92212 · dotnet/runtime · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2011,7 +2011,7 @@ void CodeGen::genEmitMachineCode()
#if TRACK_LSRA_STATS
if (JitConfig.DisplayLsraStats() == 3)
{
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout);
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand DownExpand Up@@ -2104,7 +2104,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout;
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
Expand DownExpand Up@@ -2157,7 +2157,7 @@ void CodeGen::genEmitUnwindDebugGCandEH()
fflush(dmpf);
}

if (dmpf != jitstdout)
if (dmpf != jitstdout())
{
fclose(dmpf);
}
Expand Down
342 changes: 170 additions & 172 deletions src/coreclr/jit/compiler.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -10345,7 +10345,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
InlineInfo* inlineInfo);
void compDone();

static void compDisplayStaticSizes(FILE* fout);
static void compDisplayStaticSizes();

//------------ Some utility functions --------------

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/disasm.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1478,12 +1478,12 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
}
#else // !DEBUG
// NOTE: non-DEBUG builds always use jitstdout currently!
disAsmFile = jitstdout;
disAsmFile = jitstdout();
#endif // !DEBUG

if (disAsmFile == nullptr)
{
disAsmFile = jitstdout;
disAsmFile = jitstdout();
}

// As this writes to a common file, this is not reentrant.
Expand DownExpand Up@@ -1519,7 +1519,7 @@ void DisAssembler::disAsmCode(BYTE* hotCodePtr, size_t hotCodeSize, BYTE* coldCo
DisasmBuffer(disAsmFile, /* printIt */ true);
fprintf(disAsmFile, "\n");

if (disAsmFile != jitstdout)
if (disAsmFile != jitstdout())
{
fclose(disAsmFile);
}
Expand Down
73 changes: 50 additions & 23 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

/*****************************************************************************/

FILE* jitstdout = nullptr;

ICorJitHost* g_jitHost = nullptr;
bool g_jitInitialized = false;

Expand DownExpand Up@@ -72,15 +70,28 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
assert(!JitConfig.isInitialized());
JitConfig.initialize(jitHost);

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();

g_jitInitialized = true;
}

static FILE* volatile s_jitstdout;

static FILE* jitstdoutInit()
{
const WCHAR* jitStdOutFile = JitConfig.JitStdOutFile();
FILE* file = nullptr;
if (jitStdOutFile != nullptr)
{
jitstdout = _wfopen(jitStdOutFile, W("a"));
assert(jitstdout != nullptr);
file = _wfopen(jitStdOutFile, W("a"));
assert(file != nullptr);
}

#if !defined(HOST_UNIX)
if (jitstdout == nullptr)
if (file == nullptr)
{
int stdoutFd = _fileno(procstdout());
// Check fileno error output(s) -1 may overlap with errno result
Expand All@@ -89,46 +100,61 @@ extern "C" DLLEXPORT void jitStartup(ICorJitHost* jitHost)
// or bogus and avoid making further calls.
if ((stdoutFd != -1) && (stdoutFd != -2) && (errno != EINVAL))
{
int jitstdoutFd = _dup(_fileno(procstdout()));
int jitstdoutFd = _dup(stdoutFd);
// Check the error status returned by dup.
if (jitstdoutFd != -1)
{
_setmode(jitstdoutFd, _O_TEXT);
jitstdout = _fdopen(jitstdoutFd, "w");
assert(jitstdout != nullptr);
file = _fdopen(jitstdoutFd, "w");
assert(file != nullptr);

// Prevent the FILE* from buffering its output in order to avoid calls to
// `fflush()` throughout the code.
setvbuf(jitstdout, nullptr, _IONBF, 0);
setvbuf(file, nullptr, _IONBF, 0);
}
}
}
#endif // !HOST_UNIX

// If jitstdout is still null, fallback to whatever procstdout() was
// initially set to.
if (jitstdout == nullptr)
if (file == nullptr)
{
jitstdout = procstdout();
file = procstdout();
}

#ifdef FEATURE_TRACELOGGING
JitTelemetry::NotifyDllProcessAttach();
#endif
Compiler::compStartup();
FILE* observed = InterlockedCompareExchangeT(&s_jitstdout, file, nullptr);

g_jitInitialized = true;
if (observed != nullptr)
{
if (file != procstdout())
{
fclose(file);
}

return observed;
}

return file;
}

#ifndef DEBUG
FILE* jitstdout()
{
FILE* file = s_jitstdout;
if (file != nullptr)
{
return file;
}

return jitstdoutInit();
}

// Like printf/logf, but only outputs to jitstdout -- skips call back into EE.
void jitprintf(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(jitstdout, fmt, vl);
vfprintf(jitstdout(), fmt, vl);
va_end(vl);
}
#endif

void jitShutdown(bool processIsTerminating)
{
Expand All@@ -139,14 +165,15 @@ void jitShutdown(bool processIsTerminating)

Compiler::compShutdown();

if (jitstdout != procstdout())
FILE* file = s_jitstdout;
if ((file != nullptr) && (file != procstdout()))
{
// When the process is terminating, the fclose call is unnecessary and is also prone to
// crashing since the UCRT itself often frees the backing memory earlier on in the
// termination sequence.
if (!processIsTerminating)
{
fclose(jitstdout);
fclose(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,7 +215,7 @@ unsigned emitter::emitInt32CnsCnt;
unsigned emitter::emitNegCnsCnt;
unsigned emitter::emitPow2CnsCnt;

void emitterStaticStats(FILE* fout)
void emitterStaticStats()
{
// The IG buffer size depends on whether we are storing a debug info pointer or not. For our purposes
// here, do not include that.
Expand All@@ -227,6 +227,8 @@ void emitterStaticStats(FILE* fout)

insGroup* igDummy = nullptr;

FILE* fout = jitstdout();

fprintf(fout, "\n");
fprintf(fout, "insGroup:\n");
fprintf(fout, "Offset / size of igNext = %3zu / %2zu\n", offsetof(insGroup, igNext),
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -387,7 +387,7 @@ int logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
written = vflogf(jitstdout, fmt, args);
written = vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand DownExpand Up@@ -448,7 +448,7 @@ void gcDump_logf(const char* fmt, ...)
{
// if the EE refuses to log it, we try to send it to stdout
va_start(args, fmt);
vflogf(jitstdout, fmt, args);
vflogf(jitstdout(), fmt, args);
va_end(args);
}
#if 0 // Enable this only when you need it
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -674,7 +674,7 @@ FILE* Compiler::fgOpenFlowGraphFile(bool* wbDontClose, Phases phase, PhasePositi
}
else if (strcmp(filename, "stdout") == 0)
{
fgxFile = jitstdout;
fgxFile = jitstdout();
*wbDontClose = true;
}
else if (strcmp(filename, "stderr") == 0)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,10 +481,12 @@ void GenTree::ReportOperBashing(FILE* f)

#if MEASURE_NODE_SIZE

void GenTree::DumpNodeSizes(FILE* fp)
void GenTree::DumpNodeSizes()
{
// Dump the sizes of the various GenTree flavors

FILE* fp = jitstdout();

fprintf(fp, "Small tree node size = %zu bytes\n", TREE_NODE_SZ_SMALL);
fprintf(fp, "Large tree node size = %zu bytes\n", TREE_NODE_SZ_LARGE);
fprintf(fp, "\n");
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -2311,7 +2311,7 @@ struct GenTree
void SetIndirExceptionFlags(Compiler* comp);

#if MEASURE_NODE_SIZE
static void DumpNodeSizes(FILE* fp);
static void DumpNodeSizes();
#endif

#ifdef DEBUG
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/host.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@

/*****************************************************************************/

void jitprintf(const char* fmt, ...);

#ifdef DEBUG

#undef printf
Expand DownExpand Up@@ -44,7 +46,6 @@ extern "C" void ANALYZER_NORETURN __cdecl assertAbort(const char* why, const cha
// Re-define printf in Release to use jitstdout (can be overwritten with DOTNET_JitStdOutFile=file)
#undef printf
#define printf jitprintf
void jitprintf(const char* fmt, ...);

#undef assert
#define assert(p) (void)0
Expand All@@ -55,7 +56,7 @@ void jitprintf(const char* fmt, ...);
#define _HOST_H_
/*****************************************************************************/

extern FILE* jitstdout;
FILE* jitstdout();

inline FILE* procstdout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/inline.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -480,7 +480,7 @@ void InlineContext::DumpData(unsigned indent)
{
const char* inlineReason = InlGetObservationString(m_Observation);
printf("%*s%u,\"%s\",\"%s\",", indent, "", GetOrdinal(), inlineReason, calleeName);
m_Policy->DumpData(jitstdout);
m_Policy->DumpData(jitstdout());
printf("\n");
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1421,7 +1421,7 @@ PhaseStatus LinearScan::doLinearScan()
#endif
)
{
dumpLsraStats(jitstdout);
dumpLsraStats(jitstdout());
}
#endif // TRACK_LSRA_STATS

Expand Down