V8 Project
v8::SourceGroup Class Reference

#include <d8.h>

+ Collaboration diagram for v8::SourceGroup:

Classes

class  IsolateThread
 

Public Member Functions

 SourceGroup ()
 
 ~SourceGroup ()
 
void Begin (char **argv, int offset)
 
void End (int offset)
 
void Execute (Isolate *isolate)
 
void StartExecuteInThread ()
 
void WaitForThread ()
 

Private Member Functions

void ExecuteInThread ()
 
void ExitShell (int exit_code)
 
Handle< StringReadFile (Isolate *isolate, const char *name)
 

Static Private Member Functions

static base::Thread::Options GetThreadOptions ()
 

Private Attributes

base::Semaphore next_semaphore_
 
base::Semaphore done_semaphore_
 
base::Threadthread_
 
const char ** argv_
 
int begin_offset_
 
int end_offset_
 

Detailed Description

Definition at line 117 of file d8.h.

Constructor & Destructor Documentation

◆ SourceGroup()

v8::SourceGroup::SourceGroup ( )
inline

Definition at line 119 of file d8.h.

119  :
120 #ifndef V8_SHARED
121  next_semaphore_(0),
122  done_semaphore_(0),
123  thread_(NULL),
124 #endif // !V8_SHARED
125  argv_(NULL),
126  begin_offset_(0),
127  end_offset_(0) {}
base::Thread * thread_
Definition: d8.h:163
base::Semaphore done_semaphore_
Definition: d8.h:162
base::Semaphore next_semaphore_
Definition: d8.h:161
int end_offset_
Definition: d8.h:171
const char ** argv_
Definition: d8.h:169
int begin_offset_
Definition: d8.h:170
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

◆ ~SourceGroup()

v8::SourceGroup::~SourceGroup ( )

Definition at line 1176 of file d8.cc.

1176  {
1177 #ifndef V8_SHARED
1178  delete thread_;
1179  thread_ = NULL;
1180 #endif // !V8_SHARED
1181 }

References NULL.

Member Function Documentation

◆ Begin()

void v8::SourceGroup::Begin ( char **  argv,
int  offset 
)
inline

Definition at line 131 of file d8.h.

131  {
132  argv_ = const_cast<const char**>(argv);
133  begin_offset_ = offset;
134  }

References argv_, and begin_offset_.

Referenced by v8::Shell::SetOptions().

+ Here is the caller graph for this function:

◆ End()

void v8::SourceGroup::End ( int  offset)
inline

Definition at line 136 of file d8.h.

136 { end_offset_ = offset; }

References end_offset_.

Referenced by v8::Shell::SetOptions().

+ Here is the caller graph for this function:

◆ Execute()

void v8::SourceGroup::Execute ( Isolate isolate)

Definition at line 1184 of file d8.cc.

1184  {
1185  bool exception_was_thrown = false;
1186  for (int i = begin_offset_; i < end_offset_; ++i) {
1187  const char* arg = argv_[i];
1188  if (strcmp(arg, "-e") == 0 && i + 1 < end_offset_) {
1189  // Execute argument given to -e option directly.
1190  HandleScope handle_scope(isolate);
1191  Handle<String> file_name = String::NewFromUtf8(isolate, "unnamed");
1192  Handle<String> source = String::NewFromUtf8(isolate, argv_[i + 1]);
1193  if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
1194  exception_was_thrown = true;
1195  break;
1196  }
1197  ++i;
1198  } else if (arg[0] == '-') {
1199  // Ignore other options. They have been parsed already.
1200  } else {
1201  // Use all other arguments as names of files to load and run.
1202  HandleScope handle_scope(isolate);
1203  Handle<String> file_name = String::NewFromUtf8(isolate, arg);
1204  Handle<String> source = ReadFile(isolate, arg);
1205  if (source.IsEmpty()) {
1206  printf("Error reading '%s'\n", arg);
1207  Shell::Exit(1);
1208  }
1209  if (!Shell::ExecuteString(isolate, source, file_name, false, true)) {
1210  exception_was_thrown = true;
1211  break;
1212  }
1213  }
1214  }
1215  if (exception_was_thrown != Shell::options.expected_to_throw) {
1216  Shell::Exit(1);
1217  }
1218 }
static void Exit(int exit_code)
Definition: d8.cc:991
static bool ExecuteString(Isolate *isolate, Handle< String > source, Handle< Value > name, bool print_result, bool report_exceptions)
Definition: d8.cc:211
static ShellOptions options
Definition: d8.h:365
Handle< String > ReadFile(Isolate *isolate, const char *name)
Definition: d8.cc:1221
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-8 data.
Definition: api.cc:5447

References v8::Shell::ExecuteString(), v8::Shell::Exit(), v8::Handle< T >::IsEmpty(), v8::String::NewFromUtf8(), v8::Shell::options, and v8::internal::ReadFile().

+ Here is the call graph for this function:

◆ ExecuteInThread()

void v8::SourceGroup::ExecuteInThread ( )
private

Definition at line 1242 of file d8.cc.

1242  {
1243  Isolate* isolate = Isolate::New();
1244  do {
1245  next_semaphore_.Wait();
1246  {
1247  Isolate::Scope iscope(isolate);
1248  {
1249  HandleScope scope(isolate);
1250  PerIsolateData data(isolate);
1251  Local<Context> context = Shell::CreateEvaluationContext(isolate);
1252  {
1253  Context::Scope cscope(context);
1254  PerIsolateData::RealmScope realm_scope(PerIsolateData::Get(isolate));
1255  Execute(isolate);
1256  }
1257  }
1258  if (Shell::options.send_idle_notification) {
1259  const int kLongIdlePauseInMs = 1000;
1260  isolate->ContextDisposedNotification();
1261  isolate->IdleNotification(kLongIdlePauseInMs);
1262  }
1263  if (Shell::options.invoke_weak_callbacks) {
1264  // By sending a low memory notifications, we will try hard to collect
1265  // all garbage and will therefore also invoke all weak callbacks of
1266  // actually unreachable persistent handles.
1267  isolate->LowMemoryNotification();
1268  }
1269  }
1270  done_semaphore_.Signal();
1271  } while (!Shell::options.last_run);
1272 
1273  isolate->Dispose();
1274 }
static Isolate * New(const CreateParams &params=CreateParams())
Creates a new isolate.
Definition: api.cc:6583
friend class RealmScope
Definition: d8.cc:103
static PerIsolateData * Get(Isolate *isolate)
Definition: d8.cc:89
static Local< Context > CreateEvaluationContext(Isolate *isolate)
Definition: d8.cc:960
void Execute(Isolate *isolate)
Definition: d8.cc:1184

References v8::Isolate::ContextDisposedNotification(), v8::Shell::CreateEvaluationContext(), v8::Isolate::Dispose(), v8::PerIsolateData::Get(), v8::Isolate::IdleNotification(), v8::Isolate::LowMemoryNotification(), v8::Isolate::New(), and v8::Shell::options.

Referenced by v8::SourceGroup::IsolateThread::Run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExitShell()

void v8::SourceGroup::ExitShell ( int  exit_code)
private

◆ GetThreadOptions()

base::Thread::Options v8::SourceGroup::GetThreadOptions ( )
staticprivate

Definition at line 1233 of file d8.cc.

1233  {
1234  // On some systems (OSX 10.6) the stack size default is 0.5Mb or less
1235  // which is not enough to parse the big literal expressions used in tests.
1236  // The stack size should be at least StackGuard::kLimitSize + some
1237  // OS-specific padding for thread startup code. 2Mbytes seems to be enough.
1238  return base::Thread::Options("IsolateThread", 2 * MB);
1239 }
const int MB
Definition: d8.cc:164

References v8::MB.

◆ ReadFile()

Handle< String > v8::SourceGroup::ReadFile ( Isolate isolate,
const char *  name 
)
private

Definition at line 1221 of file d8.cc.

1221  {
1222  int size;
1223  char* chars = ReadChars(isolate, name, &size);
1224  if (chars == NULL) return Handle<String>();
1225  Handle<String> result =
1227  delete[] chars;
1228  return result;
1229 }
@ kNormalString
Definition: v8.h:1963
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
static char * ReadChars(Isolate *isolate, const char *name, int *size_out)
Definition: d8.cc:1077

References v8::String::kNormalString, name, v8::String::NewFromUtf8(), NULL, v8::ReadChars(), and size.

+ Here is the call graph for this function:

◆ StartExecuteInThread()

void v8::SourceGroup::StartExecuteInThread ( )

Definition at line 1277 of file d8.cc.

1277  {
1278  if (thread_ == NULL) {
1279  thread_ = new IsolateThread(this);
1280  thread_->Start();
1281  }
1282  next_semaphore_.Signal();
1283 }

References NULL.

◆ WaitForThread()

void v8::SourceGroup::WaitForThread ( )

Definition at line 1286 of file d8.cc.

1286  {
1287  if (thread_ == NULL) return;
1288  if (Shell::options.last_run) {
1289  thread_->Join();
1290  } else {
1291  done_semaphore_.Wait();
1292  }
1293 }

References NULL, and v8::Shell::options.

Member Data Documentation

◆ argv_

const char** v8::SourceGroup::argv_
private

Definition at line 169 of file d8.h.

Referenced by Begin().

◆ begin_offset_

int v8::SourceGroup::begin_offset_
private

Definition at line 170 of file d8.h.

Referenced by Begin().

◆ done_semaphore_

base::Semaphore v8::SourceGroup::done_semaphore_
private

Definition at line 162 of file d8.h.

◆ end_offset_

int v8::SourceGroup::end_offset_
private

Definition at line 171 of file d8.h.

Referenced by End().

◆ next_semaphore_

base::Semaphore v8::SourceGroup::next_semaphore_
private

Definition at line 161 of file d8.h.

◆ thread_

base::Thread* v8::SourceGroup::thread_
private

Definition at line 163 of file d8.h.


The documentation for this class was generated from the following files: