Bug 589169: fix some aot code in runtests (p=jstpierre@mecheye.net, cpeyer; r=brbaker)
[tamarin-stm.git] / shell / avmshell.h
blobce4e66295e557f8846e30457c67c9521f37959c3
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 #ifdef VMCFG_AOT
94 #include "../aot/AOTCompiler.h"
95 #endif
97 namespace avmshell
99 class ByteArray;
100 class Shell;
101 class ShellCodeContext;
102 class ShellCore;
103 class ShellCoreImpl;
104 class ShellSettings;
105 class ShellToplevel;
108 #include "Selftest.h"
109 #include "Platform.h"
110 #include "File.h"
112 #include "FileInputStream.h"
113 #include "ConsoleOutputStream.h"
114 #include "SystemClass.h"
115 #include "FileClass.h"
116 #include "DomainClass.h"
117 #include "DebugCLI.h"
118 #include "Profiler.h"
119 #include "DataIO.h"
120 #include "ByteArrayGlue.h"
121 #include "DictionaryGlue.h"
122 #include "SamplerScript.h"
123 #include "JavaGlue.h"
124 #include "ShellCore.h"
126 namespace avmshell
128 // The stack margin is the amount of stack that should be available to native
129 // code that does not itself check for stack overflow. The execution engines
130 // in the VM will reserve this amount of stack.
132 #ifdef AVMPLUS_64BIT
133 const size_t kStackMargin = 262144;
134 #elif (defined AVMPLUS_WIN32 && defined UNDER_CE) || defined AVMPLUS_SYMBIAN
135 // FIXME: all embedded platforms, but we have no way of expressing that now
136 const size_t kStackMargin = 32768;
137 #else
138 const size_t kStackMargin = 131072;
139 #endif
141 // The fallback stack size is probably not safe but is used by the shell code
142 // if it fails to obtain the stack size from the operating system.
143 // 512KB is the traditional value.
145 const size_t kStackSizeFallbackValue = 512*1024;
147 // exit codes
148 enum {
149 OUT_OF_MEMORY = 128
152 // swf support, impl code in swf.cpp
153 bool isSwf(ScriptBuffer);
154 void handleSwf(const char *, ScriptBuffer, Toplevel*, CodeContext*);
156 #ifdef VMCFG_AOT
157 // AOT support, impl code in aot.cpp
158 void handleAOT(AvmCore*, Domain*, DomainEnv*, Toplevel*, CodeContext*);
159 #endif
161 class ShellSettings : public ShellCoreSettings
163 public:
164 ShellSettings();
166 char* programFilename; // name of the executable, or NULL
167 char** filenames; // non-terminated array of file names, never NULL
168 int numfiles; // number of entries in 'filenames'
169 bool do_selftest;
170 bool do_repl;
171 bool do_log;
172 bool do_projector;
173 int numthreads;
174 int numworkers;
175 int repeats;
176 uint32_t stackSize;
177 char st_mem[200]; // Selftest scratch memory. 200 chars ought to be enough for anyone
181 * Shell driver and command line parser.
183 class Shell {
184 public:
185 static int run(int argc, char *argv[]);
187 private:
188 static void singleWorker(ShellSettings& settings);
189 static void singleWorkerHelper(ShellCore* shell, ShellSettings& settings);
190 #ifdef VMCFG_WORKERTHREADS
191 static void multiWorker(ShellSettings& settings);
192 #endif
193 static void repl(ShellCore* shellCore);
194 static void initializeLogging(const char* basename);
195 static void parseCommandLine(int argc, char* argv[], ShellSettings& settings);
196 static void usage();
201 * A subclass of ShellCore that provides an implementation of setStackLimit().
203 class ShellCoreImpl : public ShellCore {
204 public:
206 * @param gc The garbage collector for this core
207 * @param mainthread True if this core is being used on the main thread and not on a spawned
208 * thread. It must be one or the other; a core created on a spawned thread
209 * cannot be used on the main thread or vice versa.
211 ShellCoreImpl(MMgc::GC* gc, ShellSettings& settings, bool mainthread);
214 * Set AvmCore::minstack appropriately for the current thread.
216 virtual void setStackLimit();
218 private:
219 ShellSettings& settings;
220 bool mainthread;
224 #endif /* __avmshell__ */