]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - profiler/ProfilerDatabase.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / profiler / ProfilerDatabase.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2012, 2013 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 ProfilerDatabase_h
27#define ProfilerDatabase_h
28
29#include "JSCJSValue.h"
30#include "ProfilerBytecodes.h"
31#include "ProfilerCompilation.h"
32#include "ProfilerCompilationKind.h"
33#include <wtf/FastAllocBase.h>
34#include <wtf/HashMap.h>
35#include <wtf/Noncopyable.h>
36#include <wtf/PassRefPtr.h>
37#include <wtf/SegmentedVector.h>
38#include <wtf/text/WTFString.h>
39
40namespace JSC { namespace Profiler {
41
42class Database {
43 WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(Database);
44public:
45 JS_EXPORT_PRIVATE Database(VM&);
46 JS_EXPORT_PRIVATE ~Database();
47
48 int databaseID() const { return m_databaseID; }
49
50 Bytecodes* ensureBytecodesFor(CodeBlock*);
51 void notifyDestruction(CodeBlock*);
52
53 PassRefPtr<Compilation> newCompilation(CodeBlock*, CompilationKind);
54 PassRefPtr<Compilation> newCompilation(Bytecodes*, CompilationKind);
55
56 // Converts the database to a JavaScript object that is suitable for JSON stringification.
57 // Note that it's probably a good idea to use an ExecState* associated with a global
58 // object that is "clean" - i.e. array and object prototypes haven't had strange things
59 // done to them. And yes, it should be appropriate to just use a globalExec here.
60 JS_EXPORT_PRIVATE JSValue toJS(ExecState*) const;
61
62 // Converts the database to a JavaScript object using a private temporary global object,
63 // and then returns the JSON representation of that object.
64 JS_EXPORT_PRIVATE String toJSON() const;
65
66 // Saves the JSON representation (from toJSON()) to the given file. Returns false if the
67 // save failed.
68 JS_EXPORT_PRIVATE bool save(const char* filename) const;
69
70 void registerToSaveAtExit(const char* filename);
71
72private:
73
74 void addDatabaseToAtExit();
75 void removeDatabaseFromAtExit();
76 void performAtExitSave() const;
77 static Database* removeFirstAtExitDatabase();
78 static void atExitCallback();
79
80 int m_databaseID;
81 VM& m_vm;
82 SegmentedVector<Bytecodes> m_bytecodes;
83 HashMap<CodeBlock*, Bytecodes*> m_bytecodesMap;
84 Vector<RefPtr<Compilation> > m_compilations;
85 bool m_shouldSaveAtExit;
86 CString m_atExitSaveFilename;
87 Database* m_nextRegisteredDatabase;
88};
89
90} } // namespace JSC::Profiler
91
92#endif // ProfilerDatabase_h
93