1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qv4functiontable_p.h"
5#include "qv4function_p.h"
6
7#include <assembler/MacroAssemblerCodeRef.h>
8
9#include <QtCore/qfile.h>
10#include <QtCore/qcoreapplication.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace QV4 {
15
16void generateFunctionTable(Function *function, JSC::MacroAssemblerCodeRef *codeRef)
17{
18 // This implements writing of JIT'd addresses so that perf can find the
19 // symbol names.
20 //
21 // Perf expects the mapping to be in a certain place and have certain
22 // content, for more information, see:
23 // https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
24 static bool doProfile = !qEnvironmentVariableIsEmpty(varName: "QV4_PROFILE_WRITE_PERF_MAP");
25 if (Q_UNLIKELY(doProfile)) {
26 static QFile perfMapFile(QString::fromLatin1(ba: "/tmp/perf-%1.map")
27 .arg(a: QCoreApplication::applicationPid()));
28 static const bool isOpen = perfMapFile.open(flags: QIODevice::WriteOnly);
29 if (!isOpen) {
30 qWarning(msg: "QV4::JIT::Assembler: Cannot write perf map file.");
31 doProfile = false;
32 } else {
33 const void *address = codeRef->code().executableAddress();
34 perfMapFile.write(data: QByteArray::number(reinterpret_cast<quintptr>(address), base: 16));
35 perfMapFile.putChar(c: ' ');
36 perfMapFile.write(data: QByteArray::number(static_cast<qsizetype>(codeRef->size()), base: 16));
37 perfMapFile.putChar(c: ' ');
38 perfMapFile.write(data: Function::prettyName(function, address).toUtf8());
39 perfMapFile.putChar(c: '\n');
40 perfMapFile.flush();
41 }
42 }
43}
44
45void destroyFunctionTable(Function *function, JSC::MacroAssemblerCodeRef *codeRef)
46{
47 Q_UNUSED(function);
48 Q_UNUSED(codeRef);
49
50 // It's not advisable to remove things from the perf map file, as it's primarily used to analyze
51 // a trace after the application has terminated. We want to know about all functions that were
52 // ever jitted then. If the memory ranges overlap, we will have a problem when analyzing the
53 // trace. The JIT should try to avoid this.
54}
55
56size_t exceptionHandlerSize()
57{
58 return 0;
59}
60
61} // QV4
62
63QT_END_NAMESPACE
64

source code of qtdeclarative/src/qml/jsruntime/qv4functiontable_unix.cpp