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 SystemClass::SystemClass(VTable
*cvtable
)
46 : ClassClosure(cvtable
)
48 ShellCore
* core
= (ShellCore
*)this->core();
49 if (core
->systemClass
== NULL
) {
50 core
->systemClass
= this;
53 createVanillaPrototype();
55 // initialTime: support for getTimer
56 // todo note this is currently routed to the performance counter
57 // for benchmark purposes.
58 #ifdef PERFORMANCE_GETTIMER
59 initialTime
= VMPI_getPerformanceCounter();
61 initialTime
= VMPI_getTime();
62 #endif // PERFORMANCE_GETTIMER
66 SystemClass::~SystemClass()
71 void SystemClass::exit(int status
)
73 Platform::GetInstance()->exit(status
);
76 int SystemClass::exec(Stringp command
)
79 toplevel()->throwArgumentError(kNullArgumentError
, "command");
85 StUTF8String
commandUTF8(command
);
86 return system(commandUTF8
.c_str());
90 Stringp
SystemClass::getAvmplusVersion()
92 return core()->newConstantStringLatin1(AVMPLUS_VERSION_USER
" " AVMPLUS_BUILD_CODE
);
95 void SystemClass::write(Stringp s
)
98 toplevel()->throwArgumentError(kNullArgumentError
, "string");
102 void SystemClass::trace(ArrayObject
* a
)
105 toplevel()->throwArgumentError(kNullArgumentError
, "array");
106 AvmCore
* core
= this->core();
107 PrintWriter
& console
= core
->console
;
108 for (int i
=0, n
= a
->getLength(); i
< n
; i
++)
112 StringIndexer
s(core
->string(a
->getUintProperty(i
)));
113 for (int j
= 0; j
< s
->length(); j
++)
116 // '\r' gets converted into '\n'
117 // '\n' is left alone
118 // '\r\n' is left alone
121 if (((j
+1) < s
->length()) && s
[j
+1] == '\n')
138 void SystemClass::debugger()
141 if (core()->debugger())
142 core()->debugger()->enterDebugger();
146 bool SystemClass::isDebugger()
149 return core()->debugger() != NULL
;
155 unsigned SystemClass::getTimer()
157 #ifdef PERFORMANCE_GETTIMER
158 double time
= ((double) (VMPI_getPerformanceCounter() - initialTime
) * 1000.0 /
159 (double)VMPI_getPerformanceFrequency());
160 return (uint32_t)time
;
162 return (uint32_t)(VMPI_getTime() - initialTime
);
163 #endif /* PERFORMANCE_GETTIMER */
167 int SystemClass::user_argc
;
168 char **SystemClass::user_argv
;
170 ArrayObject
* SystemClass::getArgv()
172 // get VTable for avmplus.System
173 Toplevel
*toplevel
= this->toplevel();
174 AvmCore
*core
= this->core();
176 ArrayObject
*array
= toplevel
->arrayClass
->newArray();
177 for(int i
=0; i
<user_argc
;i
++)
178 array
->setUintProperty(i
, core
->newStringUTF8(user_argv
[i
])->atom());
183 Stringp
SystemClass::readLine()
185 AvmCore
* core
= this->core();
186 Stringp s
= core
->kEmptyString
;
189 for (int c
= getchar(); c
!= '\n' && c
!= EOF
; c
= getchar())
205 double SystemClass::get_totalMemory()
207 MMgc::GCHeap
* gcheap
= MMgc::GCHeap::GetGCHeap();
208 return double(gcheap
->GetTotalHeapSize() * MMgc::GCHeap::kBlockSize
);
211 double SystemClass::get_freeMemory()
213 MMgc::GCHeap
* gcheap
= MMgc::GCHeap::GetGCHeap();
214 return double(gcheap
->GetFreeHeapSize() * MMgc::GCHeap::kBlockSize
);
217 double SystemClass::get_privateMemory()
219 return double(VMPI_getPrivateResidentPageCount() * VMPI_getVMPageSize());
222 void SystemClass::forceFullCollection()
224 core()->GetGC()->Collect();
227 void SystemClass::queueCollection()
229 core()->GetGC()->QueueCollection();
232 bool SystemClass::isGlobal(Atom o
)
234 return AvmCore::isObject(o
) ? AvmCore::atomToScriptObject(o
)->isGlobalObject() : false;