summaryrefslogtreecommitdiff
path: root/src/env-inl.h
diff options
context:
space:
mode:
authorMike Kaufman <mike.kaufman@microsoft.com>2017-08-25 12:45:00 -0700
committerAnna Henningsen <anna@addaleax.net>2017-09-13 17:44:24 +0200
commit35a526c1d4702d54c464510f448879f096a97321 (patch)
treed5147ecaf5e86bc429af38f01d994d4b2edd5fdf /src/env-inl.h
parent2ac7b433b42dd44b319e1113e045dda8df20a4f8 (diff)
downloadandroid-node-v8-35a526c1d4702d54c464510f448879f096a97321.tar.gz
android-node-v8-35a526c1d4702d54c464510f448879f096a97321.tar.bz2
android-node-v8-35a526c1d4702d54c464510f448879f096a97321.zip
http2,async-wrap: introduce AliasedBuffer class
This change introduces an AliasedBuffer class and updates asytnc-wrap and http2 to use this class. A common technique to optimize performance is to create a native buffer and then map that native buffer to user space via JS array. The runtime can efficiently write to the native buffer without having to route though JS, and the values being written are accessible from user space. While efficient, this technique allows modifications to user space memory w/out going through JS type system APIs, effectively bypassing any monitoring the JS VM has in place to track program state modifications. The result is that monitors have an incorrect view of prorgram state. The AliasedBuffer class provides a future placeholder where this technique can be used, but writes can still be observed. To achieve this, the node-chakra-core fork will add in appropriate tracking logic in the AliasedBuffer's SetValue() method. Going forward, this class can evolve to support more sophisticated mechanisms if necessary. PR-URL: https://github.com/nodejs/node/pull/15077 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/env-inl.h')
-rw-r--r--src/env-inl.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index d31b3602e9..555e1f6f5a 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -24,6 +24,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+#include "aliased_buffer.h"
#include "env.h"
#include "node.h"
#include "util.h"
@@ -82,8 +83,8 @@ inline uint32_t* IsolateData::zero_fill_field() const {
inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate)
: isolate_(isolate),
- fields_(),
- uid_fields_() {
+ fields_(isolate, kFieldsCount),
+ uid_fields_(isolate, kUidFieldsCount) {
v8::HandleScope handle_scope(isolate_);
// kAsyncUidCntr should start at 1 because that'll be the id the execution
@@ -105,7 +106,8 @@ inline Environment::AsyncHooks::AsyncHooks(v8::Isolate* isolate)
#undef V
}
-inline uint32_t* Environment::AsyncHooks::fields() {
+inline AliasedBuffer<uint32_t, v8::Uint32Array>&
+Environment::AsyncHooks::fields() {
return fields_;
}
@@ -113,7 +115,8 @@ inline int Environment::AsyncHooks::fields_count() const {
return kFieldsCount;
}
-inline double* Environment::AsyncHooks::uid_fields() {
+inline AliasedBuffer<double, v8::Float64Array>&
+Environment::AsyncHooks::uid_fields() {
return uid_fields_;
}
@@ -147,7 +150,7 @@ inline bool Environment::AsyncHooks::pop_ids(double async_id) {
fprintf(stderr,
"Error: async hook stack has become corrupted ("
"actual: %.f, expected: %.f)\n",
- uid_fields_[kCurrentAsyncId],
+ uid_fields_.GetValue(kCurrentAsyncId),
async_id);
Environment* env = Environment::GetCurrent(isolate_);
DumpBacktrace(stderr);
@@ -346,7 +349,7 @@ inline Environment::~Environment() {
delete[] heap_statistics_buffer_;
delete[] heap_space_statistics_buffer_;
delete[] http_parser_buffer_;
- free(http2_state_buffer_);
+ delete http2_state_;
free(performance_state_);
}
@@ -445,7 +448,9 @@ inline std::vector<double>* Environment::destroy_ids_list() {
}
inline double Environment::new_async_id() {
- return ++async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr];
+ async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr] =
+ async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr] + 1;
+ return async_hooks()->uid_fields()[AsyncHooks::kAsyncUidCntr];
}
inline double Environment::current_async_id() {
@@ -457,7 +462,8 @@ inline double Environment::trigger_id() {
}
inline double Environment::get_init_trigger_id() {
- double* uid_fields = async_hooks()->uid_fields();
+ AliasedBuffer<double, v8::Float64Array>& uid_fields =
+ async_hooks()->uid_fields();
double tid = uid_fields[AsyncHooks::kInitTriggerId];
uid_fields[AsyncHooks::kInitTriggerId] = 0;
if (tid <= 0) tid = current_async_id();
@@ -497,13 +503,13 @@ inline void Environment::set_http_parser_buffer(char* buffer) {
http_parser_buffer_ = buffer;
}
-inline http2::http2_state* Environment::http2_state_buffer() const {
- return http2_state_buffer_;
+inline http2::http2_state* Environment::http2_state() const {
+ return http2_state_;
}
-inline void Environment::set_http2_state_buffer(http2::http2_state* buffer) {
- CHECK_EQ(http2_state_buffer_, nullptr); // Should be set only once.
- http2_state_buffer_ = buffer;
+inline void Environment::set_http2_state(http2::http2_state* buffer) {
+ CHECK_EQ(http2_state_, nullptr); // Should be set only once.
+ http2_state_ = buffer;
}
inline double* Environment::fs_stats_field_array() const {