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
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.
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 ***** */
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
52 #define VMCFG_WORKERTHREADS
55 #if defined VMCFG_TESTING
56 // We simulate Flash's use of API versioning for testing only.
57 #define VMCFG_TEST_VERSIONING
60 #if !defined(UNDER_CE) && !defined(AVM_SHELL_NO_PROJECTOR)
61 # define AVMSHELL_PROJECTOR_SUPPORT
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
68 #pragma warning(disable:4996) // 'scanf' was declared deprecated
71 // forward declarations for shell_toplevel.h
79 class StackFrameObject
;
80 class NewObjectSampleObject
;
84 #include "shell_toplevel.h"
86 using namespace avmplus
;
96 class ShellCodeContext
;
103 #include "Selftest.h"
104 #include "Platform.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"
115 #include "DictionaryGlue.h"
116 #include "SamplerScript.h"
117 #include "JavaGlue.h"
118 #include "ShellCore.h"
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.
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;
132 const size_t kStackMargin
= 131072;
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;
146 // swf support, impl code in swf.cpp
147 bool isSwf(ScriptBuffer
);
148 void handleSwf(const char *, ScriptBuffer
, Toplevel
*, CodeContext
*);
151 // AOT support, impl code in aot.cpp
152 void handleAOT(AvmCore
*, Domain
*, DomainEnv
*, Toplevel
*, CodeContext
*);
155 class ShellSettings
: public ShellCoreSettings
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'
171 char st_mem
[200]; // Selftest scratch memory. 200 chars ought to be enough for anyone
175 * Shell driver and command line parser.
179 static int run(int argc
, char *argv
[]);
182 static void singleWorker(ShellSettings
& settings
);
183 static void singleWorkerHelper(ShellCore
* shell
, ShellSettings
& settings
);
184 #ifdef VMCFG_WORKERTHREADS
185 static void multiWorker(ShellSettings
& settings
);
187 static void repl(ShellCore
* shellCore
);
188 static void initializeLogging(const char* basename
);
189 static void parseCommandLine(int argc
, char* argv
[], ShellSettings
& settings
);
195 * A subclass of ShellCore that provides an implementation of setStackLimit().
197 class ShellCoreImpl
: public ShellCore
{
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();
213 ShellSettings
& settings
;
218 #endif /* __avmshell__ */