ebbb7c4134
compatible with webkit and will allow for easy externalization of strings. One byte strings are retained for pure ASCII strings. (The language specification was changed recently to reflect this as follows "A string is a sequence of UTF-16 code units"). - Remove four byte string class and all references to it. - Rename some of the string functions in Dart API to make them consistent and better describe the underlying functionality Dart_NewString => Dart_NewStringFromCString Dart_NewString8 => Dart_NewStringFromUTF8 Dart_NewString16 => Dart_NewStringFromUTF16 Dart_NewString32 => Dart_NewStringFromUTF32 Dart_NewExternalString8 => Dart_NewExternalUTF8String Dart_NewExternalString16 => Dart_NewExternalUTF16String Dart_NewExternalString32 => Dart_NewExternalUTF32String Dart_StringGet8 => Dart_StringToUTF8 Dart_StringGet16 => Dart_StringToUTF16 Dart_StringToCString => Dart_StringToCString Dart_IsString8 => Removed Dart_IsString16 -> Removed Dart_StringToBytes -> Removed Dart_StringGet32 -> Removed Review URL: https://codereview.chromium.org//11318018 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14357 260f80e4-7a28-3924-810f-c04153c831b5
120 lines
3.5 KiB
C++
120 lines
3.5 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef VM_BENCHMARK_TEST_H_
|
|
#define VM_BENCHMARK_TEST_H_
|
|
|
|
#include "include/dart_api.h"
|
|
|
|
#include "vm/dart.h"
|
|
#include "vm/globals.h"
|
|
#include "vm/heap.h"
|
|
#include "vm/isolate.h"
|
|
#include "vm/object.h"
|
|
#include "vm/zone.h"
|
|
|
|
namespace dart {
|
|
|
|
DECLARE_FLAG(int, code_heap_size);
|
|
DECLARE_FLAG(int, heap_growth_space_ratio);
|
|
|
|
// The BENCHMARK macro is used for benchmarking a specific functionality
|
|
// of the VM
|
|
#define BENCHMARK(name) \
|
|
void Dart_Benchmark##name(Benchmark* benchmark); \
|
|
static const Benchmark kRegister##name(Dart_Benchmark##name, #name); \
|
|
static void Dart_BenchmarkHelper##name(Benchmark* benchmark); \
|
|
void Dart_Benchmark##name(Benchmark* benchmark) { \
|
|
FLAG_heap_growth_space_ratio = 100; \
|
|
BenchmarkIsolateScope __isolate__(benchmark); \
|
|
StackZone __zone__(benchmark->isolate()); \
|
|
HandleScope __hs__(benchmark->isolate()); \
|
|
Dart_BenchmarkHelper##name(benchmark); \
|
|
} \
|
|
static void Dart_BenchmarkHelper##name(Benchmark* benchmark)
|
|
|
|
|
|
inline Dart_Handle NewString(const char* str) {
|
|
return Dart_NewStringFromCString(str);
|
|
}
|
|
|
|
|
|
class Benchmark {
|
|
public:
|
|
typedef void (RunEntry)(Benchmark* benchmark);
|
|
|
|
Benchmark(RunEntry* run, const char* name) :
|
|
run_(run),
|
|
name_(name),
|
|
score_(0),
|
|
isolate_(NULL),
|
|
next_(NULL) {
|
|
if (first_ == NULL) {
|
|
first_ = this;
|
|
} else {
|
|
tail_->next_ = this;
|
|
}
|
|
tail_ = this;
|
|
}
|
|
|
|
// Accessors.
|
|
const char* name() const { return name_; }
|
|
void set_score(intptr_t value) { score_ = value; }
|
|
intptr_t score() const { return score_; }
|
|
Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); }
|
|
|
|
Dart_Isolate CreateIsolate(uint8_t* buffer) {
|
|
char* err = NULL;
|
|
isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, &err);
|
|
EXPECT(isolate_ != NULL);
|
|
free(err);
|
|
return isolate_;
|
|
}
|
|
|
|
void Run() { (*run_)(this); }
|
|
void RunBenchmark();
|
|
|
|
static void RunAll(const char* executable);
|
|
static void SetExecutable(const char* arg) { executable_ = arg; }
|
|
static const char* Executable() { return executable_; }
|
|
|
|
private:
|
|
static Benchmark* first_;
|
|
static Benchmark* tail_;
|
|
static const char* executable_;
|
|
|
|
RunEntry* const run_;
|
|
const char* name_;
|
|
intptr_t score_;
|
|
Dart_Isolate isolate_;
|
|
Benchmark* next_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Benchmark);
|
|
};
|
|
|
|
|
|
class BenchmarkIsolateScope {
|
|
public:
|
|
explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) {
|
|
benchmark_->CreateIsolate(NULL);
|
|
Dart_EnterScope(); // Create a Dart API scope for unit benchmarks.
|
|
}
|
|
~BenchmarkIsolateScope() {
|
|
Dart_ExitScope(); // Exit the Dart API scope created for unit tests.
|
|
ASSERT(benchmark_->isolate() == Isolate::Current());
|
|
Dart_ShutdownIsolate();
|
|
benchmark_ = NULL;
|
|
}
|
|
Benchmark* benchmark() const { return benchmark_; }
|
|
|
|
private:
|
|
Benchmark* benchmark_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // VM_BENCHMARK_TEST_H_
|