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
;
94 #include "../aot/AOTCompiler.h"
101 class ShellCodeContext
;
108 #include "Selftest.h"
109 #include "Platform.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"
120 #include "ByteArrayGlue.h"
121 #include "DictionaryGlue.h"
122 #include "SamplerScript.h"
123 #include "JavaGlue.h"
124 #include "ShellCore.h"
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.
133 const size_t kStackMargin
= 262144;
134 #elif (defined AVMPLUS_WIN32 && defined UNDER_CE) || defined VMCFG_SYMBIAN
135 // FIXME: all embedded platforms, but we have no way of expressing that now
136 const size_t kStackMargin
= 32768;
138 const size_t kStackMargin
= 131072;
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;
152 // swf support, impl code in swf.cpp
153 bool isSwf(ScriptBuffer
);
154 void handleSwf(const char *, ScriptBuffer
, Toplevel
*, CodeContext
*);
157 // AOT support, impl code in aot.cpp
158 void handleAOT(AvmCore
*, Domain
*, DomainEnv
*, Toplevel
*, CodeContext
*);
161 class ShellSettings
: public ShellCoreSettings
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'
177 char st_mem
[200]; // Selftest scratch memory. 200 chars ought to be enough for anyone
181 * Shell driver and command line parser.
185 static int run(int argc
, char *argv
[]);
188 static void singleWorker(ShellSettings
& settings
);
189 static void singleWorkerHelper(ShellCore
* shell
, ShellSettings
& settings
);
190 #ifdef VMCFG_WORKERTHREADS
191 static void multiWorker(ShellSettings
& settings
);
193 static void repl(ShellCore
* shellCore
);
194 static void initializeLogging(const char* basename
);
195 static void parseCommandLine(int argc
, char* argv
[], ShellSettings
& settings
);
201 * A subclass of ShellCore that provides an implementation of setStackLimit().
203 class ShellCoreImpl
: public ShellCore
{
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();
219 ShellSettings
& settings
;
224 #endif /* __avmshell__ */