Bug 591908: Remove Math.floor from microbenchmark iterations/sec calculation (r=fklockii)
[tamarin-stm.git] / shell / avmshell.h
blobed5191793c804e7325526a63d76bac344b7d09cf
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmshell__
41 #define __avmshell__
43 #include "avmplus.h"
45 #if defined AVMPLUS_MAC || defined AVMPLUS_UNIX
46 // Support for the -workers switch and distributing files across
47 // multiple AvmCores on multiple threads. Only the code in the
48 // shell depends on this setting; the AVM core code works out of
49 // the box.
51 // Requires pthreads.
52 #define VMCFG_WORKERTHREADS
53 #endif
55 #if defined VMCFG_TESTING
56 // We simulate Flash's use of API versioning for testing only.
57 #define VMCFG_TEST_VERSIONING
58 #endif
60 #if !defined(UNDER_CE) && !defined(AVM_SHELL_NO_PROJECTOR)
61 # define AVMSHELL_PROJECTOR_SUPPORT
62 #endif
64 #define INT32_T_MAX 0x7FFFFFFF //max value for a 32-bit integer
65 #define UINT32_T_MAX 0xFFFFFFFF //max value for a 32-bit unsigned integer
67 #ifdef _MSC_VER
68 #pragma warning(disable:4996) // 'scanf' was declared deprecated
69 #endif
71 // forward declarations for shell_toplevel.h
72 namespace avmshell
74 class SystemClass;
76 namespace avmplus
78 class SampleObject;
79 class StackFrameObject;
80 class NewObjectSampleObject;
81 class TraceClass;
84 #include "shell_toplevel.h"
86 using namespace avmplus;
88 namespace avmplus
90 class Dictionary;
93 namespace avmshell
95 class Shell;
96 class ShellCodeContext;
97 class ShellCore;
98 class ShellCoreImpl;
99 class ShellSettings;
100 class ShellToplevel;
103 #include "Selftest.h"
104 #include "Platform.h"
105 #include "File.h"
107 #include "FileInputStream.h"
108 #include "ConsoleOutputStream.h"
109 #include "SystemClass.h"
110 #include "FileClass.h"
111 #include "DomainClass.h"
112 #include "DebugCLI.h"
113 #include "Profiler.h"
114 #include "DataIO.h"
115 #include "DictionaryGlue.h"
116 #include "SamplerScript.h"
117 #include "JavaGlue.h"
118 #include "ShellCore.h"
120 namespace avmshell
122 // The stack margin is the amount of stack that should be available to native
123 // code that does not itself check for stack overflow. The execution engines
124 // in the VM will reserve this amount of stack.
126 #ifdef AVMPLUS_64BIT
127 const size_t kStackMargin = 262144;
128 #elif (defined AVMPLUS_WIN32 && defined UNDER_CE) || defined VMCFG_SYMBIAN
129 // FIXME: all embedded platforms, but we have no way of expressing that now
130 const size_t kStackMargin = 32768;
131 #else
132 const size_t kStackMargin = 131072;
133 #endif
135 // The fallback stack size is probably not safe but is used by the shell code
136 // if it fails to obtain the stack size from the operating system.
137 // 512KB is the traditional value.
139 const size_t kStackSizeFallbackValue = 512*1024;
141 // exit codes
142 enum {
143 OUT_OF_MEMORY = 128
146 // swf support, impl code in swf.cpp
147 bool isSwf(ScriptBuffer);
148 void handleSwf(const char *, ScriptBuffer, Toplevel*, CodeContext*);
150 #ifdef VMCFG_AOT
151 // AOT support, impl code in aot.cpp
152 void handleAOT(AvmCore*, Domain*, DomainEnv*, Toplevel*, CodeContext*);
153 #endif
155 class ShellSettings : public ShellCoreSettings
157 public:
158 ShellSettings();
160 char* programFilename; // name of the executable, or NULL
161 char** filenames; // non-terminated array of file names, never NULL
162 int numfiles; // number of entries in 'filenames'
163 bool do_selftest;
164 bool do_repl;
165 bool do_log;
166 bool do_projector;
167 int numthreads;
168 int numworkers;
169 int repeats;
170 uint32_t stackSize;
171 char st_mem[200]; // Selftest scratch memory. 200 chars ought to be enough for anyone
175 * Shell driver and command line parser.
177 class Shell {
178 public:
179 static int run(int argc, char *argv[]);
181 private:
182 static void singleWorker(ShellSettings& settings);
183 static void singleWorkerHelper(ShellCore* shell, ShellSettings& settings);
184 #ifdef VMCFG_WORKERTHREADS
185 static void multiWorker(ShellSettings& settings);
186 #endif
187 static void repl(ShellCore* shellCore);
188 static void initializeLogging(const char* basename);
189 static void parseCommandLine(int argc, char* argv[], ShellSettings& settings);
190 static void usage();
195 * A subclass of ShellCore that provides an implementation of setStackLimit().
197 class ShellCoreImpl : public ShellCore {
198 public:
200 * @param gc The garbage collector for this core
201 * @param mainthread True if this core is being used on the main thread and not on a spawned
202 * thread. It must be one or the other; a core created on a spawned thread
203 * cannot be used on the main thread or vice versa.
205 ShellCoreImpl(MMgc::GC* gc, ShellSettings& settings, bool mainthread);
208 * Set AvmCore::minstack appropriately for the current thread.
210 virtual void setStackLimit();
212 private:
213 ShellSettings& settings;
214 bool mainthread;
218 #endif /* __avmshell__ */