DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (fbecf6c8a86f)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is [Open Source Virtual Machine.].
 *
 * The Initial Developer of the Original Code is
 * Adobe System Incorporated.
 * Portions created by the Initial Developer are Copyright (C) 2004-2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Adobe AS3 Team
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#ifndef __avmshell__
#define __avmshell__

#include "avmplus.h"

#if defined AVMPLUS_MAC || defined AVMPLUS_UNIX
  // Support for the -workers switch and distributing files across
  // multiple AvmCores on multiple threads.  Only the code in the
  // shell depends on this setting; the AVM core code works out of
  // the box.
  //
  // Requires pthreads.
  #define VMCFG_WORKERTHREADS
#endif

#if defined VMCFG_TESTING
  // We simulate Flash's use of API versioning for testing only.
  #define VMCFG_TEST_VERSIONING
#endif

#if !defined(UNDER_CE) && !defined(AVM_SHELL_NO_PROJECTOR)
#  define AVMSHELL_PROJECTOR_SUPPORT
#endif

#define INT32_T_MAX		0x7FFFFFFF	//max value for a 32-bit integer
#define UINT32_T_MAX	0xFFFFFFFF	//max value for a 32-bit unsigned integer

#ifdef _MSC_VER
#pragma warning(disable:4996)		// 'scanf' was declared deprecated
#endif

// forward declarations for shell_toplevel.h
namespace avmshell
{
	class SystemClass;
}
namespace avmplus
{
	class SampleObject;
	class StackFrameObject;
	class NewObjectSampleObject;
	class TraceClass;
}

#include "shell_toplevel.h"

using namespace avmplus;

namespace avmplus
{
	class Dictionary;
}

#ifdef VMCFG_AOT
#include "../aot/AOTCompiler.h"
#endif

namespace avmshell
{
	class ByteArray;
	class Shell;
	class ShellCodeContext;
	class ShellCore;
	class ShellCoreImpl;
	class ShellSettings;
	class ShellToplevel;
}

#include "Selftest.h"
#include "Platform.h"
#include "File.h"

#include "FileInputStream.h"
#include "ConsoleOutputStream.h"
#include "SystemClass.h"
#include "FileClass.h"
#include "DomainClass.h"
#include "DebugCLI.h"
#include "Profiler.h"
#include "DataIO.h"
#include "ByteArrayGlue.h"
#include "DictionaryGlue.h"
#include "SamplerScript.h"
#include "JavaGlue.h"
#include "ShellCore.h"

namespace avmshell
{ 
	// The stack margin is the amount of stack that should be available to native
	// code that does not itself check for stack overflow.  The execution engines
	// in the VM will reserve this amount of stack.
	
#ifdef AVMPLUS_64BIT
	const size_t kStackMargin = 262144;
#elif (defined AVMPLUS_WIN32 && defined UNDER_CE) || defined AVMPLUS_SYMBIAN
	// FIXME: all embedded platforms, but we have no way of expressing that now
	const size_t kStackMargin = 32768;
#else
	const size_t kStackMargin = 131072;
#endif
	
	// The fallback stack size is probably not safe but is used by the shell code
	// if it fails to obtain the stack size from the operating system.
	// 512KB is the traditional value.

	const size_t kStackSizeFallbackValue = 512*1024;

	// exit codes
	enum {
		OUT_OF_MEMORY = 128,
	};
	
	// swf support, impl code in swf.cpp
	bool isSwf(ScriptBuffer);
	void handleSwf(const char *, ScriptBuffer, DomainEnv*, Toplevel*&, CodeContext*);

#ifdef VMCFG_AOT
	// AOT support, impl code in aot.cpp
    void handleAOT(AvmCore*, Domain*, DomainEnv*, Toplevel*&, CodeContext*);
#endif

	class ShellSettings : public ShellCoreSettings
	{
	public:
		ShellSettings();
		
		char* programFilename;			// name of the executable, or NULL
		char** filenames;				// non-terminated array of file names, never NULL
		int numfiles;					// number of entries in 'filenames'
		bool do_selftest;
		bool do_repl;
		bool do_log;
		bool do_projector;
		int numthreads;
		int numworkers;
		int repeats;
		uint32_t stackSize;
		char st_mem[200];				// Selftest scratch memory.  200 chars ought to be enough for anyone
	};
	
	/**
	 * Shell driver and command line parser.
	 */
	class Shell {
	public:
		static int run(int argc, char *argv[]);

	private:
		static void singleWorker(ShellSettings& settings);
		static void singleWorkerHelper(ShellCore* shell, ShellSettings& settings);
#ifdef VMCFG_WORKERTHREADS
		static void multiWorker(ShellSettings& settings);
#endif
		static void repl(ShellCore* shellCore);
		static void initializeLogging(const char* basename);
		static void parseCommandLine(int argc, char* argv[], ShellSettings& settings);
		static void usage();
	};
	

	/**
	 * A subclass of ShellCore that provides an implementation of setStackLimit().
	 */
	class ShellCoreImpl : public ShellCore {
	public:
		/**
		 * @param gc          The garbage collector for this core
		 * @param mainthread  True if this core is being used on the main thread and not on a spawned
		 *                    thread.  It must be one or the other; a core created on a spawned thread
		 *                    cannot be used on the main thread or vice versa.
		 */
		ShellCoreImpl(MMgc::GC* gc, ShellSettings& settings, bool mainthread);
		
		/**
		 * Set AvmCore::minstack appropriately for the current thread.
		 */
		virtual void setStackLimit();
		
	private:
		ShellSettings& settings;
		bool mainthread;
	};
}

#endif /* __avmshell__ */