source: webkit/trunk/Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp

Last change on this file was 282565, checked in by [email protected], 4 years ago

Unreviewed, reverting r282478.
https://bugs.webkit.org/show_bug.cgi?id=230358

Reverted changeset:

"Move some profiling to UnlinkedCodeBlock"
https://bugs.webkit.org/show_bug.cgi?id=230078
https://commits.webkit.org/r282478

File size: 3.8 KB
Line 
1/*
2 * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "ProfilerBytecodeSequence.h"
28
29#include "CodeBlock.h"
30#include "JSCInlines.h"
31#include <wtf/StringPrintStream.h>
32
33namespace JSC { namespace Profiler {
34
35BytecodeSequence::BytecodeSequence(CodeBlock* codeBlock)
36{
37 StringPrintStream out;
38
39 for (unsigned i = 0; i < codeBlock->numberOfArgumentValueProfiles(); ++i) {
40 ConcurrentJSLocker locker(codeBlock->m_lock);
41 CString description = codeBlock->valueProfileForArgument(i).briefDescription(locker);
42 if (!description.length())
43 continue;
44 out.reset();
45 out.print("arg", i, ": ", description);
46 m_header.append(out.toCString());
47 }
48
49 ICStatusMap statusMap;
50 codeBlock->getICStatusMap(statusMap);
51
52 for (unsigned bytecodeIndex = 0; bytecodeIndex < codeBlock->instructions().size();) {
53 out.reset();
54 codeBlock->dumpBytecode(out, bytecodeIndex, statusMap);
55 auto instruction = codeBlock->instructions().at(bytecodeIndex);
56 OpcodeID opcodeID = instruction->opcodeID();
57 m_sequence.append(Bytecode(bytecodeIndex, opcodeID, out.toCString()));
58 bytecodeIndex += instruction->size();
59 }
60}
61
62BytecodeSequence::~BytecodeSequence()
63{
64}
65
66unsigned BytecodeSequence::indexForBytecodeIndex(unsigned bytecodeIndex) const
67{
68 return binarySearch<Bytecode, unsigned>(m_sequence, m_sequence.size(), bytecodeIndex, getBytecodeIndexForBytecode) - m_sequence.begin();
69}
70
71const Bytecode& BytecodeSequence::forBytecodeIndex(unsigned bytecodeIndex) const
72{
73 return at(indexForBytecodeIndex(bytecodeIndex));
74}
75
76void BytecodeSequence::addSequenceProperties(JSGlobalObject* globalObject, JSObject* result) const
77{
78 VM& vm = globalObject->vm();
79 auto scope = DECLARE_THROW_SCOPE(vm);
80 JSArray* header = constructEmptyArray(globalObject, nullptr);
81 RETURN_IF_EXCEPTION(scope, void());
82 for (unsigned i = 0; i < m_header.size(); ++i) {
83 header->putDirectIndex(globalObject, i, jsString(vm, String::fromUTF8(m_header[i])));
84 RETURN_IF_EXCEPTION(scope, void());
85 }
86 result->putDirect(vm, vm.propertyNames->header, header);
87
88 JSArray* sequence = constructEmptyArray(globalObject, nullptr);
89 RETURN_IF_EXCEPTION(scope, void());
90 for (unsigned i = 0; i < m_sequence.size(); ++i) {
91 sequence->putDirectIndex(globalObject, i, m_sequence[i].toJS(globalObject));
92 RETURN_IF_EXCEPTION(scope, void());
93 }
94 result->putDirect(vm, vm.propertyNames->bytecode, sequence);
95}
96
97} } // namespace JSC::Profiler
98
Note: See TracBrowser for help on using the repository browser.