blob: 75b54448c9a4cd432bc849f7525350a515bcbe14 [file] [log] [blame]
sbarati@apple.comd3d0c002016-01-30 01:11:05 +00001/*
2 * Copyright (C) 2016 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#ifndef PCToCodeOriginMap_h
27#define PCToCodeOriginMap_h
28
29#if ENABLE(JIT)
30
31#include "CodeOrigin.h"
32#include "DFGCommon.h"
33#include "MacroAssembler.h"
34#include "VM.h"
35#include <wtf/Bag.h>
36#include <wtf/Optional.h>
37#include <wtf/RedBlackTree.h>
38#include <wtf/Vector.h>
39
40namespace JSC {
41
fpizlo@apple.combd1dfd42016-02-17 06:13:24 +000042#if ENABLE(FTL_JIT)
sbarati@apple.comd3d0c002016-01-30 01:11:05 +000043namespace B3 {
44class PCToOriginMap;
45}
46#endif
47
48class LinkBuffer;
49class PCToCodeOriginMapBuilder;
50
51class PCToCodeOriginMapBuilder {
52 WTF_MAKE_NONCOPYABLE(PCToCodeOriginMapBuilder);
53 friend class PCToCodeOriginMap;
54
55public:
56 PCToCodeOriginMapBuilder(VM&);
57 PCToCodeOriginMapBuilder(PCToCodeOriginMapBuilder&& other);
58
fpizlo@apple.combd1dfd42016-02-17 06:13:24 +000059#if ENABLE(FTL_JIT)
sbarati@apple.comd3d0c002016-01-30 01:11:05 +000060 PCToCodeOriginMapBuilder(VM&, B3::PCToOriginMap&&);
61#endif
62
63 void appendItem(MacroAssembler::Label, const CodeOrigin&);
64 static CodeOrigin defaultCodeOrigin() { return CodeOrigin(0, nullptr); }
65
66 bool didBuildMapping() const { return m_shouldBuildMapping; }
67
68private:
69
70 struct CodeRange {
71 MacroAssembler::Label start;
72 MacroAssembler::Label end;
73 CodeOrigin codeOrigin;
74 };
75
76 VM& m_vm;
77 Vector<CodeRange> m_codeRanges;
78 bool m_shouldBuildMapping;
79};
80
81class PCToCodeOriginMap {
82 WTF_MAKE_NONCOPYABLE(PCToCodeOriginMap);
83public:
84 PCToCodeOriginMap(PCToCodeOriginMapBuilder&&, LinkBuffer&);
85 ~PCToCodeOriginMap();
86
87 Optional<CodeOrigin> findPC(void* pc) const;
88
89 double memorySize();
90
91private:
92 size_t m_compressedPCBufferSize;
93 size_t m_compressedCodeOriginsSize;
94 uint8_t* m_compressedPCs;
95 uint8_t* m_compressedCodeOrigins;
96 uintptr_t m_pcRangeStart;
97 uintptr_t m_pcRangeEnd;
98};
99
100} // namespace JSC
101
102#endif // ENABLE(JIT)
103
104#endif // PCToCodeOriginMap_h