Re: [v8-users] Re: Intercepting the setting of static and instance methods

2020-03-04 Thread Darin Dimitrov
I was able to achieve this by exposing some internal functionality. 
Normally there's already a SetHandler method on a FunctionTemplate but it 
is not available in the public API: 
https://source.chromium.org/chromium/chromium/src/+/master:v8/src/objects/templates-inl.h;l=72;drc=b892cf58e162a8f66cd76d7472f129fe0fb6a7d1;bpv=1;bpt=1

After exposing it, I was able to intercept the setting of any property on 
my function.
 

On Tuesday, March 3, 2020 at 11:39:34 PM UTC+2, Darin Dimitrov wrote:
>
> Ben, yes, unfortunately the SetAccessor method doesn't allow intercepting 
> the setting of any arbitrary member (property or function) on the function.
>
>
> On Tuesday, March 3, 2020 at 11:21:00 PM UTC+2, Ben Noordhuis wrote:
>>
>> On Tue, Mar 3, 2020 at 1:20 PM Darin Dimitrov  
>> wrote: 
>> > 
>> > I tried every possible method but cannot intercept setting members on a 
>> Local instance. Also couldn't find any example in the 
>> https://chromium.googlesource.com/v8/v8/+/refs/heads/lkgr/test/cctest/test-api-interceptors.cc
>>  
>> > 
>> > Is this simply not possible? 
>>
>> I think for Function objects, you can't do better than SetAccessor(), 
>> but that only lets you intercept a single predetermined named property 
>> and I infer you want to intercept them all. 
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/4baf297e-cc8e-4071-83f8-18ee0a58d3da%40googlegroups.com.


Re: [v8-users] Re: Intercepting the setting of static and instance methods

2020-03-03 Thread Darin Dimitrov
Ben, yes, unfortunately the SetAccessor method doesn't allow intercepting 
the setting of any arbitrary member (property or function) on the function.


On Tuesday, March 3, 2020 at 11:21:00 PM UTC+2, Ben Noordhuis wrote:
>
> On Tue, Mar 3, 2020 at 1:20 PM Darin Dimitrov  > wrote: 
> > 
> > I tried every possible method but cannot intercept setting members on a 
> Local instance. Also couldn't find any example in the 
> https://chromium.googlesource.com/v8/v8/+/refs/heads/lkgr/test/cctest/test-api-interceptors.cc
>  
> > 
> > Is this simply not possible? 
>
> I think for Function objects, you can't do better than SetAccessor(), 
> but that only lets you intercept a single predetermined named property 
> and I infer you want to intercept them all. 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/979d3f37-a5e1-4841-b013-5fcb425c240c%40googlegroups.com.


[v8-users] Re: Intercepting the setting of static and instance methods

2020-03-03 Thread Darin Dimitrov
I tried every possible method but cannot intercept setting members on a 
Local instance. Also couldn't find any example in the 
https://chromium.googlesource.com/v8/v8/+/refs/heads/lkgr/test/cctest/test-api-interceptors.cc

Is this simply not possible?




On Monday, March 2, 2020 at 11:32:50 AM UTC+2, Darin Dimitrov wrote:
>
> I managed to intercept the setting of the instance method with the 
> following:
>
> myClassTemplate->PrototypeTemplate()->SetHandler(
> NamedPropertyHandlerConfiguration(nullptr, [](Local property, Local<
> Value> value, const PropertyCallbackInfo& info) {
> printf("This will be called when setting the instance method on the 
> prototype");
> }));
>
>
> So the question remains only for the static method interception.
>
>
> On Monday, March 2, 2020 at 11:10:26 AM UTC+2, Darin Dimitrov wrote:
>>
>> I am embedding V8 in my application and registered a custom class 
>> (MyClass). I am looking for a way to intercept the setting of methods on 
>> this class.
>>
>> Here's my code:
>>
>> 
>> auto platform = platform::NewDefaultPlatform();
>> V8::InitializePlatform(platform.get());
>> V8::Initialize();
>> std::string flags = "--expose_gc --jitless";
>> V8::SetFlagsFromString(flags.c_str(), flags.size());
>> Isolate::CreateParams create_params;
>> create_params.array_buffer_allocator = ArrayBuffer::Allocator::
>> NewDefaultAllocator();
>>
>> Isolate* isolate = Isolate::New(create_params);
>> {
>> Isolate::Scope isolate_scope(isolate);
>> HandleScope handle_scope(isolate);
>>
>> Local myClassTemplate = FunctionTemplate::New(
>> isolate);
>> Local myInstanceMethodTemplate = FunctionTemplate::
>> New(isolate);
>> myClassTemplate->InstanceTemplate()->Set(v8::String::NewFromUtf8(
>> isolate, "myInstanceMethod", v8::NewStringType::kNormal).ToLocalChecked
>> (), myInstanceMethodTemplate);
>>
>> Local globalTemplate = ObjectTemplate::New(isolate);
>> globalTemplate->Set(v8::String::NewFromUtf8(isolate, "MyClass", v8::
>> NewStringType::kNormal).ToLocalChecked(), myClassTemplate);
>>
>> Local context = v8::Context::New(isolate, nullptr, 
>> globalTemplate);
>> Context::Scope context_scope(context);
>> {
>> Local myClassCtor = myClassTemplate->GetFunction(
>> context).ToLocalChecked();
>> Local myStaticMethod = v8::Function::New(context, 
>> nullptr).ToLocalChecked();
>> assert(myClassCtor->Set(context, v8::String::NewFromUtf8(isolate, 
>> "myStaticMethod", v8::NewStringType::kNormal).ToLocalChecked(), 
>> myStaticMethod).FromMaybe(false));
>>
>> std::string src = R"(
>>// I want to intercept setting this static method and raise 
>> some C++ callback when this code is executed
>>MyClass.myStaticMethod = () => { };
>>
>>// I want to intercept setting this instance method and raise 
>> some C++ callback when this code is executed
>>MyClass.prototype.myInstanceMethod = () => { };
>>)";
>>
>>Local source = v8::String::NewFromUtf8(isolate, src.
>> c_str(), v8::NewStringType::kNormal).ToLocalChecked();
>>Local

[v8-users] Re: Intercepting the setting of static and instance methods

2020-03-02 Thread Darin Dimitrov
I managed to intercept the setting of the instance method with the 
following:

myClassTemplate->PrototypeTemplate()->SetHandler(
NamedPropertyHandlerConfiguration(nullptr, [](Local property, Local<
Value> value, const PropertyCallbackInfo& info) {
printf("This will be called when setting the instance method on the 
prototype");
}));


So the question remains only for the static method interception.


On Monday, March 2, 2020 at 11:10:26 AM UTC+2, Darin Dimitrov wrote:
>
> I am embedding V8 in my application and registered a custom class 
> (MyClass). I am looking for a way to intercept the setting of methods on 
> this class.
>
> Here's my code:
>
> 
> auto platform = platform::NewDefaultPlatform();
> V8::InitializePlatform(platform.get());
> V8::Initialize();
> std::string flags = "--expose_gc --jitless";
> V8::SetFlagsFromString(flags.c_str(), flags.size());
> Isolate::CreateParams create_params;
> create_params.array_buffer_allocator = ArrayBuffer::Allocator::
> NewDefaultAllocator();
>
> Isolate* isolate = Isolate::New(create_params);
> {
> Isolate::Scope isolate_scope(isolate);
> HandleScope handle_scope(isolate);
>
> Local myClassTemplate = FunctionTemplate::New(
> isolate);
> Local myInstanceMethodTemplate = FunctionTemplate::
> New(isolate);
> myClassTemplate->InstanceTemplate()->Set(v8::String::NewFromUtf8(
> isolate, "myInstanceMethod", v8::NewStringType::kNormal).ToLocalChecked(), 
> myInstanceMethodTemplate);
>
> Local globalTemplate = ObjectTemplate::New(isolate);
> globalTemplate->Set(v8::String::NewFromUtf8(isolate, "MyClass", v8::
> NewStringType::kNormal).ToLocalChecked(), myClassTemplate);
>
> Local context = v8::Context::New(isolate, nullptr, 
> globalTemplate);
> Context::Scope context_scope(context);
> {
> Local myClassCtor = myClassTemplate->GetFunction(
> context).ToLocalChecked();
> Local myStaticMethod = v8::Function::New(context, 
> nullptr).ToLocalChecked();
> assert(myClassCtor->Set(context, v8::String::NewFromUtf8(isolate, 
> "myStaticMethod", v8::NewStringType::kNormal).ToLocalChecked(), 
> myStaticMethod).FromMaybe(false));
>
> std::string src = R"(
>// I want to intercept setting this static method and raise 
> some C++ callback when this code is executed
>MyClass.myStaticMethod = () => { };
>
>// I want to intercept setting this instance method and raise 
> some C++ callback when this code is executed
>MyClass.prototype.myInstanceMethod = () => { };
>)";
>
>Local source = v8::String::NewFromUtf8(isolate, src.
> c_str(), v8::NewStringType::kNormal).ToLocalChecked();
>Local

[v8-users] Intercepting the setting of static and instance methods

2020-03-02 Thread Darin Dimitrov
I am embedding V8 in my application and registered a custom class 
(MyClass). I am looking for a way to intercept the setting of methods on 
this class.

Here's my code:


auto platform = platform::NewDefaultPlatform();
V8::InitializePlatform(platform.get());
V8::Initialize();
std::string flags = "--expose_gc --jitless";
V8::SetFlagsFromString(flags.c_str(), flags.size());
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = ArrayBuffer::Allocator::
NewDefaultAllocator();

Isolate* isolate = Isolate::New(create_params);
{
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);

Local myClassTemplate = FunctionTemplate::New(isolate
);
Local myInstanceMethodTemplate = FunctionTemplate::New
(isolate);
myClassTemplate->InstanceTemplate()->Set(v8::String::NewFromUtf8(isolate
, "myInstanceMethod", v8::NewStringType::kNormal).ToLocalChecked(), 
myInstanceMethodTemplate);

Local globalTemplate = ObjectTemplate::New(isolate);
globalTemplate->Set(v8::String::NewFromUtf8(isolate, "MyClass", v8::
NewStringType::kNormal).ToLocalChecked(), myClassTemplate);

Local context = v8::Context::New(isolate, nullptr, 
globalTemplate);
Context::Scope context_scope(context);
{
Local myClassCtor = myClassTemplate->GetFunction(
context).ToLocalChecked();
Local myStaticMethod = v8::Function::New(context, 
nullptr).ToLocalChecked();
assert(myClassCtor->Set(context, v8::String::NewFromUtf8(isolate, 
"myStaticMethod", v8::NewStringType::kNormal).ToLocalChecked(), 
myStaticMethod).FromMaybe(false));

std::string src = R"(
   // I want to intercept setting this static method and raise some 
C++ callback when this code is executed
   MyClass.myStaticMethod = () => { };

   // I want to intercept setting this instance method and raise 
some C++ callback when this code is executed
   MyClass.prototype.myInstanceMethod = () => { };
   )";

   Local source = v8::String::NewFromUtf8(isolate, src.c_str
(), v8::NewStringType::kNormal).ToLocalChecked();
   

[v8-users] Re: WebAssembly.instantiate didn't call then nor catch in v8 embedded

2020-02-21 Thread Darin Dimitrov
I had the same problem in my Android project and used a workaround. I 
replaced the global.WebAssembly object with a Proxy and intercept the 
"compile" and "instantiate" method calls. When this method is called I 
start a new background thread which is polling the main looper to pump 
messages and run the pending microtasks. When the promise is resolved the 
background thread is destroyed.

Here's the implementation I used: 
https://github.com/NativeScript/android-runtime/blob/d11015b62df914535947957b4a29ebf9085564e7/test-app/runtime/src/main/cpp/MessageLoopTimer.cpp


On Tuesday, December 31, 2019 at 11:19:11 AM UTC+2, aimaomao wo wrote:
>
> I also encountered the same problem in v6.5 version, did you find the 
> answer
>
> 在 2019年6月3日星期一 UTC+8下午11:29:36,Jian Guo写道:
>>
>> I tried to ship WebAssembly feature in v8 7.2 for my Android Project. I 
>> have successfully imported v8 as a static library. But I came across an 
>> issue that WebAssembly didn't call either then nor catch callback. Here 
>> is my code below:
>>
>> std::unique_ptr platform;
>> v8::Isolate *isolate;
>> v8::Persistent persistentContext;
>> void runMain();
>> void runScript();
>> void _log(const v8::FunctionCallbackInfo& info) {
>>   v8::String::Utf8Value utf(isolate, info[0].As());
>>   __android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
>> }
>>
>> void JNICALL
>> Java_com_hustunique_v8demoapplication_MainActivity_initV8(JNIEnv *env, 
>> jobject /* this */) {
>>   // Initialize V8.
>>   v8::V8::InitializeICU();
>>   platform = v8::platform::NewDefaultPlatform();
>>   v8::V8::InitializePlatform(&(*platform.get()));
>>   v8::V8::Initialize();
>>   runMain();
>> }
>>
>> void runMain() {
>>   // Create a new Isolate and make it the current one.
>>
>>   v8::Isolate::CreateParams create_params;
>>   create_params.array_buffer_allocator = 
>> v8::ArrayBuffer::Allocator::NewDefaultAllocator();
>>   isolate = v8::Isolate::New(create_params);
>> //  isolate->Enter();
>>   v8::Isolate::Scope isolate_scope(isolate);
>>   v8::HandleScope scope(isolate);
>>
>>
>>   auto global_template = v8::ObjectTemplate::New(isolate);
>>   global_template->Set(v8::String::NewFromUtf8(isolate, "log"), 
>> v8::FunctionTemplate::New(isolate, _log));   // set log function here, as 
>> it is used in my sample javascript code
>>   // Enter the context for compiling and running the sample script.
>>   v8::Local context = v8::Context::New(isolate, nullptr, 
>> global_template);
>>   persistentContext.Reset(isolate, context);
>>
>>   // Run the script to get the result.
>>   runScript();
>>
>> }
>>
>> void runScript() {
>>   // sample wasm javascript code here.
>>   const char *csource = R"(
>> WebAssembly.instantiate(new 
>> Uint8Array([0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106,
>>   115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11]),
>>   {js:{_:console.log('Called from WebAssembly Hello 
>> world')}}).then(function(obj) {
>> log('Called with instance ' + obj);
>>   }).catch(function(err) {
>> log('Called with error ' + err);
>>   });
>>   )"; // should call my Hello World log and trigger the error or return 
>> the instance successfully
>>
>>   v8::HandleScope handle_scope(isolate);
>>   auto ctx = persistentContext.Get(isolate);
>>   v8::Context::Scope context_scope(ctx);
>>   v8::TryCatch try_catch(isolate);
>>   v8::Local source = v8::String::NewFromUtf8(isolate, csource,
>> 
>>  v8::NewStringType::kNormal).ToLocalChecked();
>>
>>   v8::Local script =
>>   v8::Script::Compile(ctx, source).ToLocalChecked();
>>   v8::Local result;
>>   if (!script->Run(ctx).ToLocal()) {
>> ReportException(isolate, _catch); // report exception, ignore the 
>> implementation here
>> return;
>>   }
>>   // Convert the result to an UTF8 string and print it.
>>   v8::String::Utf8Value utf8(isolate, result);
>>   __android_log_print(ANDROID_LOG_INFO, "V8Native", "%s\n", *utf8);
>>
>> }
>>
>>
>>
>> In the demo above, I got the output with Called from WebAssembly Hello 
>> world as excepted, but I couldn't get the error message nor the instance 
>> info.
>>
>> I made a simple example on the website 
>>  compared with my demo above, 
>> here is the output in the website, which can be reproduced easily I think:
>>
>>
>> Called from WebAssembly Hello world
>>>
>>> Called with error LinkError: WebAssembly.instantiate(): Import #0 
>>> module="js" function="_" error: function import requires a callable
>>>
>>
>>
>> It seems that in my demo, neither resolve nor reject was called from 
>> WebAssembly's returning promise. After checking the type of 
>> v8::Local 
>> result in runScript method, v8 runtime confirms that it is a promise 
>> object.
>>
>> I have tried several things here but none of them works:
>>
>>1. 1. call v8::Isolate::RunMicroTasks(). Nothing happened
>>2. 2. cast result to v8::Local at the end of 

[v8-users] Intercept ES6 class extensions

2020-02-20 Thread Darin Dimitrov
I am embedding V8 and execute the following javascript:

class Parent {
}

class Child extends Parent {
}


Is there some API which would allow me to register an interceptor within 
the isolate which will get executed when registering such class? In this 
case the interceptor would receive the base class that we are extending.

Another use-case is with mixins:

let myMixin = superclass => class extends superclass {
calc() {
}
}

class Parent {
}

class Child extends myMixin(Parent) {
calc() {
...
}
}


Here I would like the interceptor to receive the base class that is being 
extended and the mixin (there could be more than one).

Is this possible with the public API in v8.h?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/d6df5053-3ec2-46df-9d72-7a9dec2a6436%40googlegroups.com.


Re: [v8-users] API to intercept Promises in V8

2020-02-12 Thread Darin Dimitrov
I managed to get this working by replacing the native Promise object by 
executing the following script:

global.Promise = new Proxy(global.Promise, {
construct: function(target, args) {
const origFunc = args[0];
return new target(function(resolve, reject) {
origFunc(
value => executeOnMainThread(resolve.bind(this, value)),
reason => executeOnMainThread(reject.bind(this, reason))
);
});
}
});

In this example, I have registered the "executeOnMainThread" function on 
the global object which will call the specified js function argument on the 
main thread.

Of course if this can be achieved without replacing the global Promise 
object, that would be even better.

On Tuesday, February 11, 2020 at 10:59:40 PM UTC+2, Darin Dimitrov wrote:
>
> Hi Ben,
>
> Thanks for the reply. My program is actually a MacOS application and it 
> uses its SDK to create threads. I am using v8::Locker to ensure that only 
> one thread is accessing the isolate. And this works quite well. I can also 
> use the MacOS SDK to schedule some work on any thread. The problem I am 
> having is how to hook into V8 promises so that I can control over which 
> thread the resolve callback i executed.
>
> For example JavaScriptCore has the possibility to specify a callback when 
> initializing the global object which allows to control and customize how 
> are the promise callbacks executed: 
> https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/runtime/JSGlobalObject.cpp#L341
>
> I am looking for a similar API in V8 if it exists.
>
> On Tuesday, February 11, 2020 at 10:31:18 PM UTC+2, Ben Noordhuis wrote:
>>
>> On Tue, Feb 11, 2020 at 8:42 PM Darin Dimitrov  
>> wrote: 
>> > 
>> > I am embedding V8 in my C++ application and I have registered a custom 
>> "test" function on the global object taking a callback as parameter: 
>> > 
>> > test(function() { 
>> > console.log("callback"); 
>> > }); 
>> > 
>> > The "test" function starts a new thread and executes the callback on 
>> this thread. 
>> > 
>> > Now I can wrap this function in a Promise: 
>> > 
>> > new Promise(function(resolve, reject) { 
>> > test(resolve); 
>> > }).then(function() { 
>> > console.log("this callback is executed on the background thread 
>> created by the 'test' function"); 
>> > }); 
>> > 
>> > I am looking for a way to somehow hook into V8 promises so that they 
>> are always resolved on the main thread of my application. 
>> > 
>> > I thought that using a custom platform might help but couldn't find any 
>> useful method that I can override. It does provide the "CallOnWorkerThread" 
>> method but can I relate this to promises? Does V8 provide some API to 
>> intercept and replace the promise implementation? 
>>
>> Some additional info is needed because it's not wholly clear to me how 
>> you envision this would work. How exactly is your program using 
>> threads? 
>>
>> A V8 isolate is not reentrant. You can migrate it between threads but 
>> only one thread can enter it (and should hold a v8::Locker to ensure 
>> that it's the only one.) 
>>
>> You have some control over when microtasks (promises) are executed 
>> with isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit) and 
>> isolate->RunMicrotasks(). 
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/dabcd8ba-26e4-4095-ac15-8f1ee446c26e%40googlegroups.com.


Re: [v8-users] API to intercept Promises in V8

2020-02-11 Thread Darin Dimitrov
Hi Ben,

Thanks for the reply. My program is actually a MacOS application and it 
uses its SDK to create threads. I am using v8::Locker to ensure that only 
one thread is accessing the isolate. And this works quite well. I can also 
use the MacOS SDK to schedule some work on any thread. The problem I am 
having is how to hook into V8 promises so that I can control over which 
thread the resolve callback i executed.

For example JavaScriptCore has the possibility to specify a callback when 
initializing the global object which allows to control and customize how 
are the promise callbacks executed: 
https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/runtime/JSGlobalObject.cpp#L341

I am looking for a similar API in V8 if it exists.

On Tuesday, February 11, 2020 at 10:31:18 PM UTC+2, Ben Noordhuis wrote:
>
> On Tue, Feb 11, 2020 at 8:42 PM Darin Dimitrov  > wrote: 
> > 
> > I am embedding V8 in my C++ application and I have registered a custom 
> "test" function on the global object taking a callback as parameter: 
> > 
> > test(function() { 
> > console.log("callback"); 
> > }); 
> > 
> > The "test" function starts a new thread and executes the callback on 
> this thread. 
> > 
> > Now I can wrap this function in a Promise: 
> > 
> > new Promise(function(resolve, reject) { 
> > test(resolve); 
> > }).then(function() { 
> > console.log("this callback is executed on the background thread 
> created by the 'test' function"); 
> > }); 
> > 
> > I am looking for a way to somehow hook into V8 promises so that they are 
> always resolved on the main thread of my application. 
> > 
> > I thought that using a custom platform might help but couldn't find any 
> useful method that I can override. It does provide the "CallOnWorkerThread" 
> method but can I relate this to promises? Does V8 provide some API to 
> intercept and replace the promise implementation? 
>
> Some additional info is needed because it's not wholly clear to me how 
> you envision this would work. How exactly is your program using 
> threads? 
>
> A V8 isolate is not reentrant. You can migrate it between threads but 
> only one thread can enter it (and should hold a v8::Locker to ensure 
> that it's the only one.) 
>
> You have some control over when microtasks (promises) are executed 
> with isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit) and 
> isolate->RunMicrotasks(). 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/388db44a-528e-48b1-bb7e-e96f1d7ee4e9%40googlegroups.com.


[v8-users] API to intercept Promises in V8

2020-02-11 Thread Darin Dimitrov
I am embedding V8 in my C++ application and I have registered a custom 
"test" function on the global object taking a callback as parameter:

test(function() {
console.log("callback");   
});

The "test" function starts a new thread and executes the callback on this 
thread.

Now I can wrap this function in a Promise:

new Promise(function(resolve, reject) {
test(resolve);
}).then(function() {
console.log("this callback is executed on the background thread created 
by the 'test' function");
});

I am looking for a way to somehow hook into V8 promises so that they are 
always resolved on the main thread of my application.

I thought that using a custom platform might help but couldn't find any 
useful method that I can override. It does provide the "CallOnWorkerThread" 
method but can I relate this to promises? Does V8 provide some API to 
intercept and replace the promise implementation?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/f27fc895-fb62-481c-ab0d-a9188027d4b7%40googlegroups.com.


Re: [v8-users] WASM not working on Android (embedded)

2020-01-17 Thread Darin Dimitrov
Thanks Clemens. I would be very happy if someone more familiar could 
provide some insight.

Any pointers in the Google Chrome source code for Android would also be 
helpful. I suppose they have already faced this problem and implemented it 
properly.


On Thursday, January 16, 2020 at 3:41:22 PM UTC+2, Clemens Backes wrote:
>
> On Thu, Jan 16, 2020 at 2:23 PM Darin Dimitrov  > wrote:
>
>> Thanks Clemens. 
>>
>> This works fine but it blocks the main thread. What would be the best 
>> approach to handle this in an Android app? Would writing a custom platform 
>> help in this case?
>>
>
> I don't know about Android development, and I am not a platform expert, so 
> maybe others can chime in.
> I guess that your own platform implementation would help because you would 
> get notified of new tasks that get scheduled.
>
> On Wednesday, January 15, 2020 at 5:12:39 PM UTC+2, Clemens Hammacher 
>> wrote:
>>>
>>> Hi Darin,
>>>
>>> WebAssembly.instantiate works asynchronously, so you have to keep your 
>>> program running for a while to wait for the asynchronous result, and keep 
>>> pumping the message loop and running microtasks to actually execute the 
>>> compilation tasks and promise resolution tasks that get added from the 
>>> background. 
>>>
>>
>>>
>>> This is probably not the most elegant solution, but it works:
>>>   [...]
>>>   script->Run(context).ToLocal();
>>>   // Keep running for 10 seconds, pumping the message loop and running
>>>   // microtasks.
>>>   auto start = std::chrono::system_clock::now();
>>>   do {
>>> v8::platform::PumpMessageLoop(platform.get(), isolate);
>>>     isolate->RunMicrotasks();
>>>   } while (std::chrono::duration_cast(
>>>std::chrono::system_clock::now() - start)
>>>.count() < 10);
>>>
>>> Hope that helps,
>>> Clemens
>>>
>>>
>>> On Wed, Jan 15, 2020 at 9:15 AM Darin Dimitrov  
>>> wrote:
>>>
>>>> I have embedded V8 (7.8.279.19) inside my Android application and tried 
>>>> executing a script that compiles a WebAssembly module.
>>>>
>>>> Unfortunately the promise returned by the "WebAssembly.compile" method 
>>>> is never completed (neither the "then" or the "catch" methods are 
>>>> invoked). 
>>>> The same happens with the "WebAssembly.instantiate" method:
>>>>
>>>> std::unique_ptr platform = v8::platform::
>>>> NewDefaultPlatform();
>>>> v8::V8::InitializePlatform(platform.get());
>>>> v8::V8::Initialize();
>>>>
>>>> v8::Isolate::CreateParams create_params;
>>>> create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::
>>>> NewDefaultAllocator();
>>>> v8::Isolate* isolate = v8::Isolate::New(create_params);
>>>> v8::Isolate::Scope isolate_scope(isolate);
>>>> v8::HandleScope scope(isolate);
>>>> auto global_template = v8::ObjectTemplate::New(isolate);
>>>> global_template->Set(v8::String::NewFromUtf8(isolate, "log", v8::
>>>> NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(
>>>> isolate, [](const v8::FunctionCallbackInfo& info) {
>>>> v8::Isolate* isolate = info.GetIsolate();
>>>> v8::String::Utf8Value utf(isolate, info[0].As());
>>>> __android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
>>>> }));
>>>>
>>>> v8::Local context = v8::Context::New(isolate, nullptr, 
>>>> global_template);
>>>> v8::Context::Scope context_scope(context);
>>>> const char* csource = R"(
>>>> let bytes = new Uint8Array([
>>>> 0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106,
>>>> 115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11
>>>> ]);
>>>> log('before the call');
>>>> WebAssembly
>>>> .instantiate(bytes)
>>>> .then(obj => log('success'))
>>>> .catch(err => log('log'));
>>>> )";
>>>> v8::Local source = v8::String::NewFromUtf8(isolate, csource
>>>> , v8::NewStringType::kNormal).ToLocalChecked();
>>>> v8::Local script = v8::Script::Compile(context, source).
>>>> ToLocalChecked();
>>>> v8::Local result;
>>>> script->Run(co

Re: [v8-users] WASM not working on Android (embedded)

2020-01-16 Thread Darin Dimitrov
Thanks Clemens. 

This works fine but it blocks the main thread. What would be the best 
approach to handle this in an Android app? Would writing a custom platform 
help in this case?


On Wednesday, January 15, 2020 at 5:12:39 PM UTC+2, Clemens Hammacher wrote:
>
> Hi Darin,
>
> WebAssembly.instantiate works asynchronously, so you have to keep your 
> program running for a while to wait for the asynchronous result, and keep 
> pumping the message loop and running microtasks to actually execute the 
> compilation tasks and promise resolution tasks that get added from the 
> background. 
>

>
> This is probably not the most elegant solution, but it works:
>   [...]
>   script->Run(context).ToLocal();
>   // Keep running for 10 seconds, pumping the message loop and running
>   // microtasks.
>   auto start = std::chrono::system_clock::now();
>   do {
> v8::platform::PumpMessageLoop(platform.get(), isolate);
> isolate->RunMicrotasks();
>   } while (std::chrono::duration_cast(
>std::chrono::system_clock::now() - start)
>.count() < 10);
>
> Hope that helps,
> Clemens
>
>
> On Wed, Jan 15, 2020 at 9:15 AM Darin Dimitrov  > wrote:
>
>> I have embedded V8 (7.8.279.19) inside my Android application and tried 
>> executing a script that compiles a WebAssembly module.
>>
>> Unfortunately the promise returned by the "WebAssembly.compile" method is 
>> never completed (neither the "then" or the "catch" methods are invoked). 
>> The same happens with the "WebAssembly.instantiate" method:
>>
>> std::unique_ptr platform = v8::platform::NewDefaultPlatform
>> ();
>> v8::V8::InitializePlatform(platform.get());
>> v8::V8::Initialize();
>>
>> v8::Isolate::CreateParams create_params;
>> create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::
>> NewDefaultAllocator();
>> v8::Isolate* isolate = v8::Isolate::New(create_params);
>> v8::Isolate::Scope isolate_scope(isolate);
>> v8::HandleScope scope(isolate);
>> auto global_template = v8::ObjectTemplate::New(isolate);
>> global_template->Set(v8::String::NewFromUtf8(isolate, "log", v8::
>> NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(
>> isolate, [](const v8::FunctionCallbackInfo& info) {
>> v8::Isolate* isolate = info.GetIsolate();
>> v8::String::Utf8Value utf(isolate, info[0].As());
>> __android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
>> }));
>>
>> v8::Local context = v8::Context::New(isolate, nullptr, 
>> global_template);
>> v8::Context::Scope context_scope(context);
>> const char* csource = R"(
>> let bytes = new Uint8Array([
>> 0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106,
>> 115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11
>> ]);
>> log('before the call');
>> WebAssembly
>> .instantiate(bytes)
>> .then(obj => log('success'))
>> .catch(err => log('log'));
>> )";
>> v8::Local source = v8::String::NewFromUtf8(isolate, csource, 
>> v8::NewStringType::kNormal).ToLocalChecked();
>> v8::Local script = v8::Script::Compile(context, source).
>> ToLocalChecked();
>> v8::Local result;
>> script->Run(context).ToLocal();
>>
>>
>>
>> Do you have any idea what I might be missing here? The same javascript code 
>> works fine in the desktop browser.
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/4c766e82-892c-45f5-984a-aa9dd87f8138%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/4c766e82-892c-45f5-984a-aa9dd87f8138%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> -- 
>
> Clemens Backes
>
> Software Engineer
>
> clem...@google.com 
>
>
> Google Germany GmbH
>
> Erika-Mann-Straße 33
>
> 80636 München
>
> Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
>
> Registergericht und -nummer: Hamburg, HRB 86891
>
> Sitz der Gesellschaft: Hamburg
>
> Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten 
>

[v8-users] Re: WASM not working on Android (embedded)

2020-01-15 Thread Darin Dimitrov
It appears that the WebAssembly compilation is happening on of the 
v8::Platform's background threads and a task will be posted to the 
foreground loop to resolve the compilation promise.

So I need to pump the message loop:

while (v8::platform::PumpMessageLoop(Runtime::platform, isolate, v8::
platform::MessageLoopBehavior::kDoNotWait)) {
isolate->RunMicrotasks();
}

Now the question is what would be the best approach to implement such 
message loop inside an Android application. I initialize the v8::Isolate on 
the main thread and I cannot block it to wait for such events. I was able 
to achieve this by using a timer which executes this pumping from time to 
time but I suppose that this is not the best solution. I was wondering if 
there's some mechanism I which would notify me that there are some tasks 
accumulated on the message loop, or maybe somehow consolidate v8 platform's 
loop with Android's message loop.


On Wednesday, January 15, 2020 at 10:15:49 AM UTC+2, Darin Dimitrov wrote:
>
> I have embedded V8 (7.8.279.19) inside my Android application and tried 
> executing a script that compiles a WebAssembly module.
>
> Unfortunately the promise returned by the "WebAssembly.compile" method is 
> never completed (neither the "then" or the "catch" methods are invoked). 
> The same happens with the "WebAssembly.instantiate" method:
>
> std::unique_ptr platform = v8::platform::NewDefaultPlatform
> ();
> v8::V8::InitializePlatform(platform.get());
> v8::V8::Initialize();
>
> v8::Isolate::CreateParams create_params;
> create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::
> NewDefaultAllocator();
> v8::Isolate* isolate = v8::Isolate::New(create_params);
> v8::Isolate::Scope isolate_scope(isolate);
> v8::HandleScope scope(isolate);
> auto global_template = v8::ObjectTemplate::New(isolate);
> global_template->Set(v8::String::NewFromUtf8(isolate, "log", v8::
> NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(
> isolate, [](const v8::FunctionCallbackInfo& info) {
> v8::Isolate* isolate = info.GetIsolate();
> v8::String::Utf8Value utf(isolate, info[0].As());
> __android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
> }));
>
> v8::Local context = v8::Context::New(isolate, nullptr, 
> global_template);
> v8::Context::Scope context_scope(context);
> const char* csource = R"(
> let bytes = new Uint8Array([
> 0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106,
> 115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11
> ]);
> log('before the call');
> WebAssembly
> .instantiate(bytes)
> .then(obj => log('success'))
> .catch(err => log('log'));
> )";
> v8::Local source = v8::String::NewFromUtf8(isolate, csource, 
> v8::NewStringType::kNormal).ToLocalChecked();
> v8::Local script = v8::Script::Compile(context, source).
> ToLocalChecked();
> v8::Local result;
> script->Run(context).ToLocal();
>
>
>
> Do you have any idea what I might be missing here? The same javascript code 
> works fine in the desktop browser.
>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/b7e02e2e-3758-4d2a-a287-611f577f1b83%40googlegroups.com.


[v8-users] WASM not working on Android (embedded)

2020-01-15 Thread Darin Dimitrov
I have embedded V8 (7.8.279.19) inside my Android application and tried 
executing a script that compiles a WebAssembly module.

Unfortunately the promise returned by the "WebAssembly.compile" method is 
never completed (neither the "then" or the "catch" methods are invoked). 
The same happens with the "WebAssembly.instantiate" method:

std::unique_ptr platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();

v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::
NewDefaultAllocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
auto global_template = v8::ObjectTemplate::New(isolate);
global_template->Set(v8::String::NewFromUtf8(isolate, "log", v8::
NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, 
[](const v8::FunctionCallbackInfo& info) {
v8::Isolate* isolate = info.GetIsolate();
v8::String::Utf8Value utf(isolate, info[0].As());
__android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf);
}));

v8::Local context = v8::Context::New(isolate, nullptr, 
global_template);
v8::Context::Scope context_scope(context);
const char* csource = R"(
let bytes = new Uint8Array([
0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106,
115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11
]);
log('before the call');
WebAssembly
.instantiate(bytes)
.then(obj => log('success'))
.catch(err => log('log'));
)";
v8::Local source = v8::String::NewFromUtf8(isolate, csource, v8
::NewStringType::kNormal).ToLocalChecked();
v8::Local script = v8::Script::Compile(context, source).
ToLocalChecked();
v8::Local result;
script->Run(context).ToLocal();



Do you have any idea what I might be missing here? The same javascript code 
works fine in the desktop browser.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/4c766e82-892c-45f5-984a-aa9dd87f8138%40googlegroups.com.


[v8-users] How to properly dispose an isolate

2019-12-05 Thread Darin Dimitrov
Hello,

I am embedding V8 in my C++ application and I need to create multiple 
isolates from different background threads.

Here's my workflow:

1. Create an isolate in the main thread -> this must be a long living 
isolate (for the entire application lifetime)
2. Spawn multiple short living background threads.
3. Inside each background thread, create a new isolate using Isolate::New.
4. At the end of the thread, call isolate->Dispose.

My question is about properly disposing the short living isolates. I have 
noticed that if I call the isolate->Dispose() as a final instruction inside 
the background thread, chances are that subsequent calls to Isolate::New 
from other threads will return a pointer to an already disposed isolate. Ss 
a result of this reuse, I get heap-use-after free errors when I try to 
perform some operations on this isolate.

On the other hand, if I don't call isolate->Dispose() then each call to 
Isolate::New will return a fresh new pointer, but the memory claimed by 
this short living isolates will never be reclaimed and is leaking.

So what is the proper way to dispose the isolates? Should the Dispose call 
be made from the background thread in which the isolate was created, or I 
need to dispose it from the main thread (in which I have entered the main 
isolate). I have tried both approaches without luck.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/01d26b9e-140a-4148-9c4a-1d0901091848%40googlegroups.com.


Re: [v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-19 Thread Darin Dimitrov
The --optimize-for-size flag doesn't seem to have any effect on the result.

On Tuesday, November 19, 2019 at 9:50:33 AM UTC+2, Simon Zünd wrote:
>
> +Leszek Swirski  
>
> I am unsure what impact lazy compilation has here. There might be a weird 
> interaction with the stack frame cache. Does the flag "--optimize-for-size" 
> cause any change in the result? That flag disables the stack frame cache 
> (among other things).
>
> On Tue, Nov 19, 2019 at 8:37 AM Darin Dimitrov  > wrote:
>
>> Further narrowed it down to the "--no-lazy" runtime flag:
>>
>> Working:
>>
>> std::string flags = "--expose_gc --jitless";
>> V8::SetFlagsFromString(flags.c_str(), flags.size());
>>
>> NOT working:
>>
>> std::string flags = "--expose_gc --jitless --no-lazy";
>> V8::SetFlagsFromString(flags.c_str(), flags.size());
>>
>> Any idea why would the --no-lazy flag affect function names in stack 
>> frames? I need the --no-lazy flag because I noticed that it speeds up code 
>> cached scripts (v8::ScriptCompiler::CreateCodeCache API).
>>
>> On Tuesday, November 19, 2019 at 9:30:07 AM UTC+2, Darin Dimitrov wrote:
>>>
>>> Simon, thanks for the clarification. Does this mean that there's no 
>>> reliable way to get this information with the current V8 public API?
>>>
>>> I went ahead and wrote a simple example illustrating the issue and tried 
>>> running it on different platforms. And the results were surprising.
>>>
>>> Here's the sample code I wrote:
>>>
>>> Isolate::CreateParams create_params;
>>> create_params.array_buffer_allocator = _;
>>> Isolate* isolate = Isolate::New(create_params);
>>> Isolate::Scope isolate_scope(isolate);
>>> HandleScope handle_scope(isolate);
>>> Local globalTemplate = ObjectTemplate::New(isolate);
>>> Local context = Context::New(isolate, nullptr, 
>>> globalTemplate);
>>> context->Enter();
>>>
>>> Local captureFunc = v8::Function::New(context, 
>>> [](const FunctionCallbackInfo& info) {
>>> Isolate* isolate = info.GetIsolate();
>>> Local context = isolate->GetCurrentContext();
>>> Local exception = 
>>> Exception::Error(v8::String::NewFromUtf8(isolate, "", 
>>> NewStringType::kNormal, 0).ToLocalChecked()).As();
>>> Local stackProperty = exception->Get(context, 
>>> v8::String::NewFromUtf8(isolate, "stack", NewStringType::kNormal, 
>>> 5).ToLocalChecked()).ToLocalChecked();
>>> v8::String::Utf8Value stackStr(isolate, stackProperty);
>>> printf("%s\n\n", *stackStr);
>>> 
>>> Local stack = 
>>> v8::StackTrace::CurrentStackTrace(isolate, 10, 
>>> v8::StackTrace::StackTraceOptions::kDetailed);
>>>
>>> for (int i = 0; i < stack->GetFrameCount(); i++) {
>>> Local frame = stack->GetFrame(isolate, i);
>>> Local funcName = frame->GetFunctionName();
>>> v8::String::Utf8Value str(isolate, funcName);
>>> const char* name = *str;
>>> printf("%s (%d:%d)\n", name, frame->GetLineNumber(), 
>>> frame->GetColumn());
>>> }
>>> }).ToLocalChecked();
>>> assert(context->Global()->Set(context, 
>>> v8::String::NewFromUtf8(isolate, "captureTrace", NewStringType::kNormal, 
>>> 12).ToLocalChecked(), captureFunc).FromMaybe(false));
>>>
>>> std::string src =
>>> "(function test() {"
>>> "const viewModel = new Object();"
>>> "viewModel.onTap = () => { captureTrace(); };"
>>> "viewModel.onTap.apply(viewModel, []);"
>>> "})();";
>>> Local

Re: [v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-18 Thread Darin Dimitrov
Further narrowed it down to the "--no-lazy" runtime flag:

Working:

std::string flags = "--expose_gc --jitless";
V8::SetFlagsFromString(flags.c_str(), flags.size());

NOT working:

std::string flags = "--expose_gc --jitless --no-lazy";
V8::SetFlagsFromString(flags.c_str(), flags.size());

Any idea why would the --no-lazy flag affect function names in stack 
frames? I need the --no-lazy flag because I noticed that it speeds up code 
cached scripts (v8::ScriptCompiler::CreateCodeCache API).

On Tuesday, November 19, 2019 at 9:30:07 AM UTC+2, Darin Dimitrov wrote:
>
> Simon, thanks for the clarification. Does this mean that there's no 
> reliable way to get this information with the current V8 public API?
>
> I went ahead and wrote a simple example illustrating the issue and tried 
> running it on different platforms. And the results were surprising.
>
> Here's the sample code I wrote:
>
> Isolate::CreateParams create_params;
> create_params.array_buffer_allocator = _;
> Isolate* isolate = Isolate::New(create_params);
> Isolate::Scope isolate_scope(isolate);
> HandleScope handle_scope(isolate);
> Local globalTemplate = ObjectTemplate::New(isolate);
> Local context = Context::New(isolate, nullptr, 
> globalTemplate);
> context->Enter();
>
> Local captureFunc = v8::Function::New(context, [](const 
> FunctionCallbackInfo& info) {
> Isolate* isolate = info.GetIsolate();
> Local context = isolate->GetCurrentContext();
> Local exception = 
> Exception::Error(v8::String::NewFromUtf8(isolate, "", 
> NewStringType::kNormal, 0).ToLocalChecked()).As();
> Local stackProperty = exception->Get(context, 
> v8::String::NewFromUtf8(isolate, "stack", NewStringType::kNormal, 
> 5).ToLocalChecked()).ToLocalChecked();
> v8::String::Utf8Value stackStr(isolate, stackProperty);
> printf("%s\n\n", *stackStr);
> 
> Local stack = 
> v8::StackTrace::CurrentStackTrace(isolate, 10, 
> v8::StackTrace::StackTraceOptions::kDetailed);
>
> for (int i = 0; i < stack->GetFrameCount(); i++) {
> Local frame = stack->GetFrame(isolate, i);
> Local funcName = frame->GetFunctionName();
> v8::String::Utf8Value str(isolate, funcName);
> const char* name = *str;
> printf("%s (%d:%d)\n", name, frame->GetLineNumber(), 
> frame->GetColumn());
> }
> }).ToLocalChecked();
> assert(context->Global()->Set(context, 
> v8::String::NewFromUtf8(isolate, "captureTrace", NewStringType::kNormal, 
> 12).ToLocalChecked(), captureFunc).FromMaybe(false));
>
> std::string src =
> "(function test() {"
> "const viewModel = new Object();"
> "viewModel.onTap = () => { captureTrace(); };"
> "viewModel.onTap.apply(viewModel, []);"
> "})();";
> Local

Re: [v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-18 Thread Darin Dimitrov
Simon, thanks for the clarification. Does this mean that there's no 
reliable way to get this information with the current V8 public API?

I went ahead and wrote a simple example illustrating the issue and tried 
running it on different platforms. And the results were surprising.

Here's the sample code I wrote:

Isolate::CreateParams create_params;
create_params.array_buffer_allocator = _;
Isolate* isolate = Isolate::New(create_params);
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);
Local globalTemplate = ObjectTemplate::New(isolate);
Local context = Context::New(isolate, nullptr, globalTemplate);
context->Enter();

Local captureFunc = v8::Function::New(context, [](const 
FunctionCallbackInfo& info) {
Isolate* isolate = info.GetIsolate();
Local context = isolate->GetCurrentContext();
Local exception = 
Exception::Error(v8::String::NewFromUtf8(isolate, "", 
NewStringType::kNormal, 0).ToLocalChecked()).As();
Local stackProperty = exception->Get(context, 
v8::String::NewFromUtf8(isolate, "stack", NewStringType::kNormal, 
5).ToLocalChecked()).ToLocalChecked();
v8::String::Utf8Value stackStr(isolate, stackProperty);
printf("%s\n\n", *stackStr);

Local stack = 
v8::StackTrace::CurrentStackTrace(isolate, 10, 
v8::StackTrace::StackTraceOptions::kDetailed);

for (int i = 0; i < stack->GetFrameCount(); i++) {
Local frame = stack->GetFrame(isolate, i);
Local funcName = frame->GetFunctionName();
v8::String::Utf8Value str(isolate, funcName);
const char* name = *str;
printf("%s (%d:%d)\n", name, frame->GetLineNumber(), 
frame->GetColumn());
}
}).ToLocalChecked();
assert(context->Global()->Set(context, v8::String::NewFromUtf8(isolate, 
"captureTrace", NewStringType::kNormal, 12).ToLocalChecked(), 
captureFunc).FromMaybe(false));

std::string src =
"(function test() {"
"const viewModel = new Object();"
"viewModel.onTap = () => { captureTrace(); };"
"viewModel.onTap.apply(viewModel, []);"
"})();";

[v8-users] Getting empty function names from the "StackTrace::CurrentStackTrace" method

2019-11-18 Thread Darin Dimitrov
I am embedding V8 and trying to capture the current javascript stacktrace 
using the "v8::StackTrace::CurrentStackTrace":

Isolate* isolate = info.GetIsolate();

Local stack = v8::StackTrace::CurrentStackTrace(isolate, 10, v8
::StackTrace::StackTraceOptions::kDetailed);

*for* (*int* i = 0; i < stack->GetFrameCount(); i++) {

Local frame = stack->GetFrame(isolate, i);

Local funcName = frame->GetFunctionName();

v8::String::Utf8Value str(isolate, funcName);

*const* *char** name = *str;

printf("%s (%d:%d)\n", name, frame->GetLineNumber(), frame->GetColumn
());

}

I have placed this code inside a custom function that I have registered to 
the global scope.

Before calling my custom function, I tried logging the stack property of an 
Error object (by using : console.log(new Error().stack)) and I obtained the 
following output:

Error
at bar (file:///app/bundle.js:266:29)
at test (file:///app/bundle.js:267:15)
at Observable.onTap (file:///app/bundle.js:268:11)
at Button.notify (file:///app/vendor.js:3620:32)
at Button._emit (file:///app/vendor.js:3640:18)
at TapHandlerImpl.tap (file:///app/vendor.js:15540:19)

With the "v8::StackTrace::CurrentStackTrace" method I get:

bar (266:29)
test (267:15)
(null) (268:11)
(null) (3620:32)
(null) (3640:18)
(null) (15540:19)

I am getting empty function names from some frames, while all the other 
information is present (script name, line, column numbers, ...).

Do you know what might be the reason for getting empty function names?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/64d9e4ca-b271-4d83-aace-753c28e193f4%40googlegroups.com.


Re: [v8-users] CpuProfiler not collecting data in jitless mode (iOS)

2019-11-06 Thread Darin Dimitrov
I managed to find the reason for this. I forgot to enter the isolate after 
creating it:

isolate->Enter()

All looks good now. Sorry for the false alert.


On Wednesday, November 6, 2019 at 10:26:41 AM UTC+2, Jakob Gruber wrote:
>
> +Peter Marshall  
>
> On Wed, Nov 6, 2019 at 8:58 AM Darin Dimitrov  > wrote:
>
>> I am trying to collect function execution data using the CpuProfiler 
>> class.
>>
>> I ran the following test (taken from here 
>> https://github.com/v8/v8/blob/master/test/cctest/test-cpu-profiler.cc#L677
>> ):
>>
>> const char* src =
>> "function loop(timeout) {\n" 
>> "  this.mmm = 0;\n" 
>> "  var start = Date.now();\n" 
>> "  do {\n" 
>> "var n = 1000;\n" 
>> "while(n > 1) {\n" 
>> "  n--;\n" 
>> "  this.mmm += n * n * n;\n" 
>> "}\n" 
>> "  } while (Date.now() - start < timeout);\n" 
>> "}\n" 
>> "function delay() { loop(10); }\n" 
>> "function bar() { delay(); }\n" 
>> "function baz() { delay(); }\n" 
>> "function foo() {\n" 
>> "  delay();\n" 
>> "  bar();\n" 
>> "  delay();\n" 
>> "  baz();\n" 
>> "}\n" 
>> "function start(duration) {\n" 
>> "  var start = Date.now();\n" 
>> "  do {\n" 
>> "foo();\n" 
>> "  } while (Date.now() - start < duration);\n" 
>> "}\n"; 
>>
>> Script::Compile(context, v8::String::NewFromUtf8(isolate, src).
>> ToLocalChecked()).ToLocalChecked()->Run(context).ToLocalChecked(); 
>> Local startFunc = context->Global()->Get(context, v8::
>> String::NewFromUtf8(isolate, "start").ToLocalChecked()).ToLocalChecked().
>> As(); 
>>
>> Local title = v8::String::NewFromUtf8(isolate, "my_trace").
>> ToLocalChecked(); 
>> CpuProfiler* profiler = CpuProfiler::New(isolate); 
>> profiler->StartProfiling(title, false); 
>>
>> Local result; 
>> Local args[] = { Number::New(isolate, 200) }; 
>> assert(startFunc->Call(context, context->Global(), 1, args).ToLocal(&
>> result)); 
>>
>> const CpuProfile* profile = profiler->StopProfiling(title); 
>> const CpuProfileNode* root = profile->GetTopDownRoot(); 
>> int count = root->GetChildrenCount(); 
>> for (int i = 0; i < count; ++i) { 
>> const CpuProfileNode* child = root->GetChild(i); 
>> v8::String::Utf8Value str(isolate, child->GetFunctionName()); 
>> const char* funcName = *str; 
>> printf("%s\n", funcName); 
>> }
>>
>>
>>
>> The root CpuProfileNode contains only a single child element called 
>> "(program)".
>>
>> If I execute the same code on Android, I correctly get the following 
>> child functions: "(program)", "start" and "(garbage collector)".
>>
>> Do you have any idea what might be wrong with the CpuProfiler class in v8 
>> in jitless mode? Is CpuProfiler the correct class to use to collect 
>> function execution times or is there some newer method?
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/798f9464-88a1-464f-8fb8-6aa223ce5e57%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/798f9464-88a1-464f-8fb8-6aa223ce5e57%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/a2ef4ac8-7c6e-47ca-8cd6-2ed554d1b885%40googlegroups.com.


[v8-users] CpuProfiler not collecting data in jitless mode (iOS)

2019-11-05 Thread Darin Dimitrov
I am trying to collect function execution data using the CpuProfiler class.

I ran the following test (taken from here 
https://github.com/v8/v8/blob/master/test/cctest/test-cpu-profiler.cc#L677):

const char* src =
"function loop(timeout) {\n" 
"  this.mmm = 0;\n" 
"  var start = Date.now();\n" 
"  do {\n" 
"var n = 1000;\n" 
"while(n > 1) {\n" 
"  n--;\n" 
"  this.mmm += n * n * n;\n" 
"}\n" 
"  } while (Date.now() - start < timeout);\n" 
"}\n" 
"function delay() { loop(10); }\n" 
"function bar() { delay(); }\n" 
"function baz() { delay(); }\n" 
"function foo() {\n" 
"  delay();\n" 
"  bar();\n" 
"  delay();\n" 
"  baz();\n" 
"}\n" 
"function start(duration) {\n" 
"  var start = Date.now();\n" 
"  do {\n" 
"foo();\n" 
"  } while (Date.now() - start < duration);\n" 
"}\n"; 

Script::Compile(context, v8::String::NewFromUtf8(isolate, src).
ToLocalChecked()).ToLocalChecked()->Run(context).ToLocalChecked(); 
Local startFunc = context->Global()->Get(context, v8::String::
NewFromUtf8(isolate, "start").ToLocalChecked()).ToLocalChecked().As(); 

Local title = v8::String::NewFromUtf8(isolate, "my_trace").
ToLocalChecked(); 
CpuProfiler* profiler = CpuProfiler::New(isolate); 
profiler->StartProfiling(title, false); 

Local result; 
Local args[] = { Number::New(isolate, 200) }; 
assert(startFunc->Call(context, context->Global(), 1, args).ToLocal(
)); 

const CpuProfile* profile = profiler->StopProfiling(title); 
const CpuProfileNode* root = profile->GetTopDownRoot(); 
int count = root->GetChildrenCount(); 
for (int i = 0; i < count; ++i) { 
const CpuProfileNode* child = root->GetChild(i); 
v8::String::Utf8Value str(isolate, child->GetFunctionName()); 
const char* funcName = *str; 
printf("%s\n", funcName); 
}



The root CpuProfileNode contains only a single child element called 
"(program)".

If I execute the same code on Android, I correctly get the following child 
functions: "(program)", "start" and "(garbage collector)".

Do you have any idea what might be wrong with the CpuProfiler class in v8 
in jitless mode? Is CpuProfiler the correct class to use to collect 
function execution times or is there some newer method?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/798f9464-88a1-464f-8fb8-6aa223ce5e57%40googlegroups.com.


Re: [v8-users] Overriding platform specific logging feature

2019-10-09 Thread Darin Dimitrov
In my case, the output is specific to a particular application as I need to 
include some additional environment information to the output.

On Wednesday, October 9, 2019 at 3:40:58 PM UTC+3, Jakob Gruber wrote:
>
> Is the override specific to iOS or to a particular application? If the 
> former, why not upstream it in V8?
>
> On Wed, Oct 9, 2019 at 2:17 PM Darin Dimitrov  > wrote:
>
>> I am embedding V8 in an iOS application and I would like to override the 
>> "OS::Print" method: 
>> https://chromium.googlesource.com/v8/v8.git/+/3.7.12.26/src/platform-posix.cc#217
>>
>> This method already handles the Android case by redirecting the output to 
>> logcat:
>>
>> void OS::VPrint(const char* format, va_list args) {
>> #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
>>   __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
>> #else
>>   vprintf(format, args);
>> #endif
>> }
>>
>> What would be the best way to override this method for my platform 
>> without modifying the V8 source code (I have compiled V8 as a static 
>> library that I am linking against in my iOS application)?
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/acfff90d-6acd-47fa-984b-ebe2def46853%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/acfff90d-6acd-47fa-984b-ebe2def46853%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/bcc03135-6008-4ac8-8289-0e439e32b9b0%40googlegroups.com.


[v8-users] Overriding platform specific logging feature

2019-10-09 Thread Darin Dimitrov
I am embedding V8 in an iOS application and I would like to override the 
"OS::Print" method: 
https://chromium.googlesource.com/v8/v8.git/+/3.7.12.26/src/platform-posix.cc#217

This method already handles the Android case by redirecting the output to 
logcat:

void OS::VPrint(const char* format, va_list args) {
#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
  __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
#else
  vprintf(format, args);
#endif
}

What would be the best way to override this method for my platform without 
modifying the V8 source code (I have compiled V8 as a static library that I 
am linking against in my iOS application)?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/acfff90d-6acd-47fa-984b-ebe2def46853%40googlegroups.com.


[v8-users] Replacing constructor function

2019-09-25 Thread Darin Dimitrov
I am embedding V8 and I have the following javascript:

var TSObject = (function (_super) {
__extends(TSObject, _super);
function TSObject() {
return _super !== null && _super.apply(this, arguments) || this;
}
return TSObject;
}(String));

As an embedder, I have registered the custom "__extends" function on the 
global object and my C++ callback is successfully invoked. 

My purpose is to be able to intercept the instantiation of such objects:

var obj = new TSObject();

and to alter the type of js objects returned from the TSObject constructor 
(ideally by invoking some user provided C++ callback). Can such a hook be 
achieved from inside the "__extends" callback?

The closest I could get is provide custom constructors for the base class 
but when the "_super.apply(this, arguments)" call is made, I am losing the 
information about TSObject and I only have access to the base class.

Is there some way that I could walk the call frames and replace this 
constructor or reach the TSObject function so that I have information about 
this type? 

I can get the current callstack by using "v8::StackTrace::CurrentStackTrace" 
but this only gives me the function name as Local and I cannot 
reach the actual Local from this frame.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/959f2a23-5dd1-49fa-81c8-62b0b483ea4d%40googlegroups.com.


Re: [v8-users] Calling js functions in jitless (iOS)

2019-09-12 Thread Darin Dimitrov
I have pretty much narrowed it down and will send a repro once I remove all 
the noise from my project

On Thursday, September 12, 2019 at 5:45:19 PM UTC+3, Jakob Kummerow wrote:
>
> CC author of that commit.
>
> Darin, do you have a full repro you can share? That would be useful for 
> debugging.
>
>
> On Thu, Sep 12, 2019 at 4:36 PM Darin Dimitrov  > wrote:
>
>> I am embedding v8 in my iOS application and calling some js function:
>>
>> Local callback = ...
>>
>> std::vector> v8Args = ...
>>
>> Local result;
>>
>> TryCatch tc(isolate);
>>
>> callback->Call(context, thiz, (*int*)v8Args.size(), v8Args.data()).
>> ToLocal());
>>
>>
>> This code works pretty fine but starting from this commit 
>> https://chromium.googlesource.com/v8/v8.git/+/738d870db64a97db243e0d5856f92cc45e1c69fd
>>  my code started failing consistently with the following error:
>>
>>
>> * thread #1, queue = 'com.apple.main-thread', stop reason = 
>> EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
>>
>>   * frame #0: 0x0001031f1fe0 
>> MyProj`v8::internal::PropertyCallbackArguments::CallNamedSetter(this=0x7ffeedc03aa0,
>>  
>> interceptor=, name=, 
>> value=Handle @ 0x7ffeedc039e8) at 
>> api-arguments-inl.h:231:3 [opt]
>>
>> frame #1: 0x00010315e11d 
>> MyProj`v8::internal::__RT_impl_Runtime_StorePropertyWithInterceptor(args=Arguments
>>  
>> @ 0x7ffeedc03af0, isolate=0x00011faf8000) at ic.cc:2760:37 [opt]
>>
>> frame #2: 0x000103cd6f00 
>> MyProj`Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 64
>>
>> frame #3: 0x000103ef0ccf MyProj`Builtins_StaNamedPropertyHandler 
>> + 1679
>>
>> frame #4: 0x000103a0be52 
>> MyProj`Builtins_InterpreterEntryTrampoline + 946
>>
>> frame #5: 0x0001039fe57a MyProj`Builtins_JSEntryTrampoline + 90
>>
>> frame #6: 0x0001039fe57a MyProj`Builtins_JSEntryTrampoline + 90
>>
>> frame #7: 0x0001039fe358 MyProj`Builtins_JSEntry + 120
>>
>> frame #8: 0x000103064512 MyProj`v8::internal::(anonymous 
>> namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous 
>> namespace)::InvokeParams const&) [inlined] 
>> v8::internal::GeneratedCode> unsigned long, unsigned long, long, unsigned 
>> long**>::Call(this=, args=, args=, 
>> args=, args=, args=, 
>> args=) at simulator.h:138:12 [opt]
>>
>> frame #9: 0x000103064509 MyProj`v8::internal::(anonymous 
>> namespace)::Invoke(isolate=0x00011faf8000, 
>> params=)::InvokeParams const&) at execution.cc:266 [opt]
>>
>> frame #10: 0x000103063e27 
>> MyProj`v8::internal::Execution::Call(isolate=0x00011faf8000, 
>> callable=, receiver=, argc=1, 
>> argv=0x61a8cee0) at execution.cc:358:10 [opt]
>>
>> frame #11: 0x000102d3a80d 
>> MyProj`v8::Function::Call(this=0x7fdeee81b840, context=, 
>> recv=, argc=1, argv=0x61a8cee0) at api.cc:4840:7 [opt]
>>
>>
>>
>> And this is the crashing code: 
>> https://chromium.googlesource.com/v8/v8.git/+/738d870db64a97db243e0d5856f92cc45e1c69fd/src/api/api-arguments-inl.h#231
>>
>>
>> The crash is observed after multiple calls to this method and after some 
>> GC iterations.
>>
>> -- 
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/8fd38a54-37de-4850-8ca1-bf9544e1b345%40googlegroups.com.


[v8-users] Calling js functions in jitless (iOS)

2019-09-12 Thread Darin Dimitrov
I am embedding v8 in my iOS application and calling some js function:

Local callback = ...

std::vector> v8Args = ...

Local result;

TryCatch tc(isolate);

callback->Call(context, thiz, (*int*)v8Args.size(), v8Args.data()).ToLocal
());


This code works pretty fine but starting from this commit 
https://chromium.googlesource.com/v8/v8.git/+/738d870db64a97db243e0d5856f92cc45e1c69fd
 my code started failing consistently with the following error:


* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS 
(code=EXC_I386_GPFLT)

  * frame #0: 0x0001031f1fe0 
MyProj`v8::internal::PropertyCallbackArguments::CallNamedSetter(this=0x7ffeedc03aa0,
 
interceptor=, name=, 
value=Handle @ 0x7ffeedc039e8) at 
api-arguments-inl.h:231:3 [opt]

frame #1: 0x00010315e11d 
MyProj`v8::internal::__RT_impl_Runtime_StorePropertyWithInterceptor(args=Arguments
 
@ 0x7ffeedc03af0, isolate=0x00011faf8000) at ic.cc:2760:37 [opt]

frame #2: 0x000103cd6f00 
MyProj`Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 64

frame #3: 0x000103ef0ccf MyProj`Builtins_StaNamedPropertyHandler + 
1679

frame #4: 0x000103a0be52 MyProj`Builtins_InterpreterEntryTrampoline 
+ 946

frame #5: 0x0001039fe57a MyProj`Builtins_JSEntryTrampoline + 90

frame #6: 0x0001039fe57a MyProj`Builtins_JSEntryTrampoline + 90

frame #7: 0x0001039fe358 MyProj`Builtins_JSEntry + 120

frame #8: 0x000103064512 MyProj`v8::internal::(anonymous 
namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous 
namespace)::InvokeParams const&) [inlined] 
v8::internal::GeneratedCode::Call(this=, args=, args=, 
args=, args=, args=, 
args=) at simulator.h:138:12 [opt]

frame #9: 0x000103064509 MyProj`v8::internal::(anonymous 
namespace)::Invoke(isolate=0x00011faf8000, 
params=)::InvokeParams const&) at execution.cc:266 [opt]

frame #10: 0x000103063e27 
MyProj`v8::internal::Execution::Call(isolate=0x00011faf8000, 
callable=, receiver=, argc=1, 
argv=0x61a8cee0) at execution.cc:358:10 [opt]

frame #11: 0x000102d3a80d 
MyProj`v8::Function::Call(this=0x7fdeee81b840, context=, 
recv=, argc=1, argv=0x61a8cee0) at api.cc:4840:7 [opt]



And this is the crashing code: 
https://chromium.googlesource.com/v8/v8.git/+/738d870db64a97db243e0d5856f92cc45e1c69fd/src/api/api-arguments-inl.h#231


The crash is observed after multiple calls to this method and after some GC 
iterations.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/c7208dda-fb34-4aa0-8055-f19b56bbac1e%40googlegroups.com.


Re: [v8-users] Calling function from shared library in V8 7.7.299.11

2019-09-12 Thread Darin Dimitrov
It might be, but normally I build my .so with the exact same custom libc++ 
which I use to build my android app. I am also able to perform other 
operations on the object such as ->Get

On Thursday, September 12, 2019 at 4:16:00 PM UTC+3, Jakob Gruber wrote:
>
> Could this be another libcxx mismatch issue and 7.7 just exposes it 
> incidentally?
>
> On Thu, Sep 12, 2019 at 2:54 PM Darin Dimitrov  > wrote:
>
>> I am cross compiling V8 for android and I have created a shared library 
>> containing a simple function which adds some property to a provided object:
>>
>> extern "C" void MyFunc(Isolate* isolate, Local& obj) {
>> Local context = isolate->GetCurrentContext();
>> obj->Set(context, v8::String::NewFromUtf8(isolate, 
>> "someProp").ToLocalChecked(), Number::New(isolate, 500));
>> }
>>
>>
>> My goal  purpose is to call this function from my android application in 
>> which I have embedded V8:
>>
>>
>> typedef void (*MyCallback)(Isolate* isolate, Local& obj);
>>
>>
>> void* handle = 
>> dlopen("/data/data/com.tns.testapplication/files/app/modules/libCalc-x86_64.so",
>>  RTLD_LAZY);
>>
>> MyCallback func = reinterpret_cast(dlsym(handle, "MyFunc"));
>> Local exportsObj = Object::New(isolate);
>> func(isolate, exportsObj);
>>
>>
>> This successfully invokes "MyFunc" from the shared library and sets the 
>> "someProp" property on the passed object. 
>>
>>
>> Starting from V8 *7.7.299.11* calling obj->Set() inside the library crashes 
>> with SIGSEGV and without any stacktrace.
>>
>>
>> I have noticed that if I set the property before calling the function then 
>> it works:
>>
>>
>> exportsObj->Set(context, v8::String::NewFromUtf8(isolate, 
>> "someProp").ToLocalChecked(), v8::Null(isolate));
>> func(isolate, exportsObj);
>>
>>
>> Any idea what might have changed between the official V8 7.6 and 7.7 
>> releases that might explain this behaviour or any tips that would allow me 
>> to debug this further?
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/48a71b41-b96e-41ec-9450-fa36d6f1bb45%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/48a71b41-b96e-41ec-9450-fa36d6f1bb45%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/296771f5-3a59-4d58-be15-7ed23f1b4a1b%40googlegroups.com.


[v8-users] Calling function from shared library in V8 7.7.299.11

2019-09-12 Thread Darin Dimitrov
I am cross compiling V8 for android and I have created a shared library 
containing a simple function which adds some property to a provided object:

extern "C" void MyFunc(Isolate* isolate, Local& obj) {
Local context = isolate->GetCurrentContext();
obj->Set(context, v8::String::NewFromUtf8(isolate, 
"someProp").ToLocalChecked(), Number::New(isolate, 500));
}


My goal  purpose is to call this function from my android application in which 
I have embedded V8:


typedef void (*MyCallback)(Isolate* isolate, Local& obj);


void* handle = 
dlopen("/data/data/com.tns.testapplication/files/app/modules/libCalc-x86_64.so",
 RTLD_LAZY);

MyCallback func = reinterpret_cast(dlsym(handle, "MyFunc"));
Local exportsObj = Object::New(isolate);
func(isolate, exportsObj);


This successfully invokes "MyFunc" from the shared library and sets the 
"someProp" property on the passed object. 


Starting from V8 *7.7.299.11* calling obj->Set() inside the library crashes 
with SIGSEGV and without any stacktrace.


I have noticed that if I set the property before calling the function then it 
works:


exportsObj->Set(context, v8::String::NewFromUtf8(isolate, 
"someProp").ToLocalChecked(), v8::Null(isolate));
func(isolate, exportsObj);


Any idea what might have changed between the official V8 7.6 and 7.7 releases 
that might explain this behaviour or any tips that would allow me to debug this 
further?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/48a71b41-b96e-41ec-9450-fa36d6f1bb45%40googlegroups.com.


Re: [v8-users] Create heap snapshot for x86 from 64 bit process

2019-08-26 Thread Darin Dimitrov
Thanks Jakob, we were considering exactly this option. Just wanted to make 
sure we weren't missing something before going that way.

On Monday, August 26, 2019 at 11:51:08 AM UTC+3, Jakob Gruber wrote:
>
> On Mon, Aug 26, 2019 at 10:41 AM Darin Dimitrov  > wrote:
>
>> Is it possible to create heap snapshot using the "mksnapshot" tool for 
>> x86 or armeabi-v7a CPU architectures from a 64 bit process. If yes, what 
>> are the steps to build such "mksnapshot" executable?
>>
>
> Unfortunately, no. Cross-bitness builds are not supported at the moment. 
> Would building inside a Linux VM be an option?
>
>
>> Mac OS Catalina drops support for 32 bit executables and we would like to 
>> still be able to produce heap snapshots for x86 or armeabi-v7a 
>> architectures on this host OS.
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/v8-users/aeb27954-4333-4a50-8f0f-273dbee63923%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/v8-users/aeb27954-4333-4a50-8f0f-273dbee63923%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/07574805-58f2-491f-a811-652699c5d25c%40googlegroups.com.


[v8-users] Create heap snapshot for x86 from 64 bit process

2019-08-26 Thread Darin Dimitrov
Is it possible to create heap snapshot using the "mksnapshot" tool for x86 
or armeabi-v7a CPU architectures from a 64 bit process. If yes, what are 
the steps to build such "mksnapshot" executable?

Mac OS Catalina drops support for 32 bit executables and we would like to 
still be able to produce heap snapshots for x86 or armeabi-v7a 
architectures on this host OS.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/aeb27954-4333-4a50-8f0f-273dbee63923%40googlegroups.com.


Re: [v8-users] jitless mode broken on ARM64

2019-08-08 Thread Darin Dimitrov
Thanks for the quick tip. Shouldn't pointer compression be disabled by 
default when target_os="ios"? Or is it just some issue that will be fixed 
and we will be able to use pointer compression in jitless mode in the 
future?

On Thursday, August 8, 2019 at 7:49:16 AM UTC+3, Jakob Gruber wrote:
>
> Darin, thanks for reporting this. You can disable pointer compression with 
> the 'v8_enable_pointer_compression = false' gn flag.
>
> On Wed, Aug 7, 2019 at 5:24 PM Santiago Aboy Solanes  > wrote:
>
>> Looks to be the same as 
>> https://bugs.chromium.org/p/v8/issues/detail?id=9588
>>
>> On Wed, Aug 7, 2019 at 1:13 PM Jakob Gruber > > wrote:
>>
>>> +Santiago Aboy Solanes  
>>>
>>> On Wed, Aug 7, 2019 at 2:09 PM Darin Dimitrov >> > wrote:
>>>
>>>> I have cross compiled V8 for iOS 
>>>> <https://v8.dev/docs/cross-compile-ios> and running in "--jitless" 
>>>> <https://v8.dev/blog/jitless> mode on an arm64 device (iPhone 6).
>>>>
>>>> Everything has been working smoothly until the following commit which 
>>>> appears to have broken it: 
>>>> https://chromium.googlesource.com/v8/v8.git/+/d1a4706af97dfd1576c7eb505745c6f864f4be06
>>>>
>>>> I am getting the following error when creating the isolate:
>>>>
>>>> *#*
>>>>
>>>> *# Fatal error in , line 0*
>>>>
>>>> *# Fatal process out of memory: Failed to reserve memory for new V8 
>>>> Isolate*
>>>>
>>>> *#*
>>>>
>>>> *#*
>>>>
>>>> *#*
>>>>
>>>> *#FailureMessage Object: 0x16fa225c8*
>>>>
>>>> * C stack trace ===*
>>>>
>>>>
>>>> *0   TestApp 0x000101b19508 
>>>> v8::base::debug::StackTrace::StackTrace() + 24*
>>>>
>>>> *1   TestApp 0x000101b1bc68 
>>>> v8::platform::(anonymous namespace)::PrintStackTrace() + 24*
>>>>
>>>> *2   TestApp 0x000101b159d4 
>>>> V8_Fatal(char const*, ...) + 204*
>>>>
>>>> *3   TestApp 0x000101285124 
>>>> v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char 
>>>> const*, bool) + 88*
>>>>
>>>> *4   TestApp 0x0001014ecf38 
>>>> v8::internal::IsolateAllocator::CommitPagesForIsolate(unsigned long) + 0*
>>>>
>>>> *5   TestApp 0x0001014ed09c 
>>>> v8::internal::IsolateAllocator::IsolateAllocator(v8::internal::IsolateAllocationMode)
>>>>  
>>>> + 44*
>>>>
>>>> *6   TestApp 0x0001014f3b5c 
>>>> v8::internal::Isolate::New(v8::internal::IsolateAllocationMode) + 36*
>>>>
>>>> *7   TestApp 0x0001012a0328 
>>>> v8::Isolate::New(v8::Isolate::CreateParams const&) + 24*
>>>>
>>>> *8   TestApp 0x000101089d1c 
>>>> tns::Runtime::Init(std::__1::basic_string>>> std::__1::char_traits, std::__1::allocator > const&) + 476*
>>>>
>>>> *9   TestApp 0x000101089834 
>>>> tns::Runtime::InitAndRunMainScript(std::__1::basic_string>>> std::__1::char_traits, std::__1::allocator > const&) + 60*
>>>>
>>>> *10  TestApp 0x000101178350 
>>>> +[NativeScript start:] + 364*
>>>>
>>>> *11  TestApp 0x0001003f3b10 main + 
>>>> 80*
>>>>
>>>> *12  libdyld.dylib   0x0002021f68e0 
>>>>  + 4*
>>>>
>>>>
>>>>
>>>> From what I can see pointer compression has been enabled on ARM64 in 
>>>> this commit. Could you spot how this might have affected --jitless mode 
>>>> and 
>>>> what would be the proper way to fix it?
>>>>
>>>> -- 
>>>> -- 
>>>> v8-users mailing list
>>>> v8-u...@googlegroups.com 
>>>> http://groups.google.com/group/v8-users
>>>> --- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "v8-users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to v8-u...@googlegroups.com .
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/v8-users/600728f0-f7b1-4d16-a47a-8873ef61af97%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/v8-users/600728f0-f7b1-4d16-a47a-8873ef61af97%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/99754d9b-1422-43b0-bd40-90514177cda2%40googlegroups.com.


[v8-users] jitless mode broken on ARM64

2019-08-07 Thread Darin Dimitrov
I have cross compiled V8 for iOS  and 
running in "--jitless"  mode on an arm64 
device (iPhone 6).

Everything has been working smoothly until the following commit which 
appears to have broken it: 
https://chromium.googlesource.com/v8/v8.git/+/d1a4706af97dfd1576c7eb505745c6f864f4be06

I am getting the following error when creating the isolate:

*#*

*# Fatal error in , line 0*

*# Fatal process out of memory: Failed to reserve memory for new V8 Isolate*

*#*

*#*

*#*

*#FailureMessage Object: 0x16fa225c8*

* C stack trace ===*


*0   TestApp 0x000101b19508 
v8::base::debug::StackTrace::StackTrace() + 24*

*1   TestApp 0x000101b1bc68 
v8::platform::(anonymous namespace)::PrintStackTrace() + 24*

*2   TestApp 0x000101b159d4 
V8_Fatal(char const*, ...) + 204*

*3   TestApp 0x000101285124 
v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char 
const*, bool) + 88*

*4   TestApp 0x0001014ecf38 
v8::internal::IsolateAllocator::CommitPagesForIsolate(unsigned long) + 0*

*5   TestApp 0x0001014ed09c 
v8::internal::IsolateAllocator::IsolateAllocator(v8::internal::IsolateAllocationMode)
 
+ 44*

*6   TestApp 0x0001014f3b5c 
v8::internal::Isolate::New(v8::internal::IsolateAllocationMode) + 36*

*7   TestApp 0x0001012a0328 
v8::Isolate::New(v8::Isolate::CreateParams const&) + 24*

*8   TestApp 0x000101089d1c 
tns::Runtime::Init(std::__1::basic_string, std::__1::allocator > const&) + 476*

*9   TestApp 0x000101089834 
tns::Runtime::InitAndRunMainScript(std::__1::basic_string, std::__1::allocator > const&) + 60*

*10  TestApp 0x000101178350 
+[NativeScript start:] + 364*

*11  TestApp 0x0001003f3b10 main + 80*

*12  libdyld.dylib   0x0002021f68e0  
+ 4*



>From what I can see pointer compression has been enabled on ARM64 in this 
commit. Could you spot how this might have affected --jitless mode and what 
would be the proper way to fix it?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/600728f0-f7b1-4d16-a47a-8873ef61af97%40googlegroups.com.


[v8-users] Reducing V8 binary size in JIT-less mode

2019-07-01 Thread Darin Dimitrov
According to https://v8.dev/blog/jitless, starting from 7.4, V8 supports 
JIT-less mode making it suitable for restricted environments.

My goal is to reduce the binary size by stripping the optimizing compiler 
code which is not needed when running in this mode.

Is any configuration flag which will compile V8 in this *lightweight* mode?

Right now I am getting both "v8_base_without_compiler" and "v8_compiler" 
but I was not able to link my application without the "v8_compiler" module.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/0dd1c357-5d83-47cb-b32e-ab3e7e504d07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] How to embed the ICU data file into my application?

2019-06-11 Thread Darin Dimitrov
I have built V8 with the "v8_enable_i18n_support=true" gn flag and I can 
successfully initialize it by providing the location of the "icudtl.dat" 
file (created during the v8 build process):

bool success = V8::InitializeICU("/path_to/icudtl.dat");

I was wondering if instead of providing the location of this file on the 
file system, it is possible to pass a pointer to the contents? I would like 
to somehow embed this file into my application.

For example for the V8 heap snapshot there are the "V8::SetNativesDataBlob" 
and "V8::SetSnapshotDataBlob" APIs which allow me to directly pass a 
pointer to "natives_blob.bin" and "snapshot_blob.bin" file contents and I 
don't need to distribute them separately.

By looking at the InitializeICU 
https://chromium.googlesource.com/v8/v8.git/+/refs/heads/master/src/init/icu_util.cc#65
  
method I couldn't find any way to achieve this.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/e2688af8-89af-410f-9738-21923e91cfb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Issues cross compiling v8 for iOS

2019-05-27 Thread Darin Dimitrov
Hi Jakob,

Thanks for the quick reply. The following patch seems to resolve the issue 
with the iOS build:

*diff --git a/src/snapshot/embedded/platform-embedded-file-writer-base.cc 
b/src/snapshot/embedded/platform-embedded-file-writer-base.cc*

*index 2adb041371..20af9e28e2 100644*

*--- a/src/snapshot/embedded/platform-embedded-file-writer-base.cc*

*+++ b/src/snapshot/embedded/platform-embedded-file-writer-base.cc*

@@ -62,7 +62,7 @@ EmbeddedTargetArch ToEmbeddedTargetArch(const char* s) {

 EmbeddedTargetOs DefaultEmbeddedTargetOs() {

 #if defined(V8_OS_AIX)

   return EmbeddedTargetOs::kAIX;

-#elif defined(V8_OS_MACOSX)

+#elif defined(V8_OS_MACOSX) || defined(V8_OS_IOS)

   return EmbeddedTargetOs::kMac;

 #elif defined(V8_OS_WIN)

   return EmbeddedTargetOs::kWin;

@@ -83,7 +83,7 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {

 return EmbeddedTargetOs::kChromeOS;

   } else if (string == "fuchsia") {

 return EmbeddedTargetOs::kFuchsia;

-  } else if (string == "mac") {

+  } else if (string == "mac" || string == "ios") {

 return EmbeddedTargetOs::kMac;

   } else if (string == "win") {

 return EmbeddedTargetOs::kWin;


On Monday, May 27, 2019 at 2:49:42 PM UTC+3, Jakob Gruber wrote:
>
> Hi Darin,
>
> I've been reworking cross-compile support in mksnapshot and may 
> have missed the iOS case in OS detection 
> <https://crrev.com/c/1622854/15/src/snapshot/embedded/platform-embedded-file-writer-base.cc>.
>  
> Let me take a look and get back to you.
>
> Jakob
>
> On Mon, May 27, 2019 at 1:40 PM Darin Dimitrov  > wrote:
>
>> I am trying to cross compile V8 for iOS (
>> https://chromium.googlesource.com/v8/v8.git/+/be47fd1c37ead74cf5c4479043426e0376d3ff29)
>>  
>> as described here: https://v8.dev/docs/cross-compile-ios
>>
>> Using Mac OS 10.14.5 and XCode 10.2.1 I am getting the following error 
>> when building *embedded.S*:
>>
>> [1321/1328] ASM obj/v8_snapshot/embedded.o
>> FAILED: obj/v8_snapshot/embedded.o 
>> ../../third_party/llvm-build/Release+Asserts/bin/clang -MMD -MF obj/
>> v8_snapshot/embedded.o.d -DNO_TCMALLOC -DCHROMIUM_BUILD -
>> DCR_XCODE_VERSION=1021 -DCR_CLANG_REVISION=\"361212-67510fac-2\" 
>> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 
>> -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 
>> -DNS_BLOCK_ASSERTIONS=1 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 
>> -DENABLE_MINOR_MC -DENABLE_HANDLE_ZAPPING -DV8_USE_SNAPSHOT 
>> -DV8_CONCURRENT_MARKING -DV8_EMBEDDED_BUILTINS -DV8_WIN64_UNWINDING_INFO 
>> -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS 
>> -DV8_TARGET_ARCH_X64 -DDISABLE_UNTRUSTED_CODE_MITIGATIONS 
>> -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -I../.. -Igen 
>> -I../.. -Igen -fno-strict-aliasing --param=ssp-buffer-size=4 
>> -fstack-protector -fcolor-diagnostics -fmerge-all-constants 
>> -fcrash-diagnostics-dir=../../tools/clang/crashreports -Xclang -mllvm 
>> -Xclang -instcombine-lower-dbg-declare=0 -std=c11 -arch x86_64 -g2 
>> -isysroot 
>> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk
>>  
>> -stdlib=libc++ -mios-simulator-version-min=10 -c gen/embedded.S -o 
>> obj/v8_snapshot/embedded.o
>> gen/embedded.S:68:15: error: unexpected token in '.section' directive
>> .section .text
>>   ^
>> gen/embedded.S:379:1: error: unknown directive
>> .type Builtins_RecordWrite, @function
>> ^
>> gen/embedded.S:431:1: error: unknown directive
>> .type Builtins_EphemeronKeyBarrier, @function
>> ^
>> gen/embedded.S:448:1: error: unknown directive
>> .type Builtins_AdaptorWithBuiltinExitFrame, @function
>> ^
>> gen/embedded.S:453:1: error: unknown directive
>> .type Builtins_ArgumentsAdaptorTrampoline, @function
>> ^
>> gen/embedded.S:466:1: error: unknown directive
>> .type Builtins_CallFunction_ReceiverIsNullOrUndefined, @function
>> ^
>>  and hundreds of other similar errors ...
>>
>>
>> This was working fine with this revision: 
>> https://chromium.googlesource.com/v8/v8.git/+/e0a109c05821fa36ec20e1f25895c23baa8d64c3
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@googlegroups.com 
>> http://groups.google.com/group/v8-users
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "v8-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to v8-u...@googlegroups.com .
>> To view this discussion on the web visit 

[v8-users] Issues cross compiling v8 for iOS

2019-05-27 Thread Darin Dimitrov
I am trying to cross compile V8 for iOS (
https://chromium.googlesource.com/v8/v8.git/+/be47fd1c37ead74cf5c4479043426e0376d3ff29)
 
as described here: https://v8.dev/docs/cross-compile-ios

Using Mac OS 10.14.5 and XCode 10.2.1 I am getting the following error when 
building *embedded.S*:

[1321/1328] ASM obj/v8_snapshot/embedded.o
FAILED: obj/v8_snapshot/embedded.o 
../../third_party/llvm-build/Release+Asserts/bin/clang -MMD -MF obj/
v8_snapshot/embedded.o.d -DNO_TCMALLOC -DCHROMIUM_BUILD -DCR_XCODE_VERSION=
1021 -DCR_CLANG_REVISION=\"361212-67510fac-2\" -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DNDEBUG -DNVALGRIND 
-DDYNAMIC_ANNOTATIONS_ENABLED=0 -DNS_BLOCK_ASSERTIONS=1 
-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DENABLE_MINOR_MC 
-DENABLE_HANDLE_ZAPPING -DV8_USE_SNAPSHOT -DV8_CONCURRENT_MARKING 
-DV8_EMBEDDED_BUILTINS -DV8_WIN64_UNWINDING_INFO -DV8_DEPRECATION_WARNINGS 
-DV8_IMMINENT_DEPRECATION_WARNINGS -DV8_TARGET_ARCH_X64 
-DDISABLE_UNTRUSTED_CODE_MITIGATIONS -DV8_DEPRECATION_WARNINGS 
-DV8_IMMINENT_DEPRECATION_WARNINGS -I../.. -Igen -I../.. -Igen 
-fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector 
-fcolor-diagnostics -fmerge-all-constants 
-fcrash-diagnostics-dir=../../tools/clang/crashreports -Xclang -mllvm 
-Xclang -instcombine-lower-dbg-declare=0 -std=c11 -arch x86_64 -g2 
-isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk
 
-stdlib=libc++ -mios-simulator-version-min=10 -c gen/embedded.S -o 
obj/v8_snapshot/embedded.o
gen/embedded.S:68:15: error: unexpected token in '.section' directive
.section .text
  ^
gen/embedded.S:379:1: error: unknown directive
.type Builtins_RecordWrite, @function
^
gen/embedded.S:431:1: error: unknown directive
.type Builtins_EphemeronKeyBarrier, @function
^
gen/embedded.S:448:1: error: unknown directive
.type Builtins_AdaptorWithBuiltinExitFrame, @function
^
gen/embedded.S:453:1: error: unknown directive
.type Builtins_ArgumentsAdaptorTrampoline, @function
^
gen/embedded.S:466:1: error: unknown directive
.type Builtins_CallFunction_ReceiverIsNullOrUndefined, @function
^
 and hundreds of other similar errors ...


This was working fine with this revision: 
https://chromium.googlesource.com/v8/v8.git/+/e0a109c05821fa36ec20e1f25895c23baa8d64c3

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/aa630655-4f80-4de3-9392-2d44af42c47f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] How to set internal field on a Local

2019-03-19 Thread Darin Dimitrov
Thanks Ben!

Yes, I am aware of this but actually I need to retrieve this external data 
*before* creating an instance using the function. Here's an example:

var myFunc = MyCustomFunction; // Here MyCustomFunction is an instance of 
Local that I have registered on the global object
someCustomMethod(myFunc);

Here I am passing MyCustomFunction as parameter to the method. Inside the 
callback of this custom method I am able to retrieve its argument (which is 
a Local) and from this function I need to retrieve its external 
field.

So the question is how do I register a custom external field to this 
Local instance?

On Tuesday, March 19, 2019 at 12:07:28 PM UTC+2, Ben Noordhuis wrote:
>
> On Tue, Mar 19, 2019 at 9:41 AM Darin Dimitrov  > wrote: 
> > 
> > I am trying to associate an internal field with a Local 
> created from a Local: 
> > 
> > Local ctorFuncTemplate = 
> FunctionTemplate::New(isolate); 
> > 
> > Local ctorFunc = 
> ctorFuncTemplate->GetFunction(context).ToLocalChecked(); 
> > 
> > ctorFunc->SetInternalField(0, External::New(isolate, ptr)); 
> > 
> > 
> > This fails with "Internal field out of bounds". 
> > 
> > 
> > I am able to properly set the internal field count on object instances 
> created from this function: 
> > 
> > 
> > ctorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(1); 
> > 
> > 
> > But what would be the proper way to set the internal field count for the 
> function instance itself? 
>
> It sounds like you should pass the External as the `data` argument to 
> FunctionTemplate::New(). 
>
> You'll be able to retrieve it in the callback as 
> FunctionCallbackInfo::Data(). 
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] How to set internal field on a Local

2019-03-19 Thread Darin Dimitrov
I am trying to associate an internal field with a Local created 
from a Local:

Local ctorFuncTemplate = FunctionTemplate::New(isolate);

Local ctorFunc = 
ctorFuncTemplate->GetFunction(context).ToLocalChecked();

ctorFunc->SetInternalField(0, External::New(isolate, ptr));


This fails with "Internal field out of bounds".


I am able to properly set the internal field count on object instances 
created from this function:


ctorFuncTemplate->InstanceTemplate()->SetInternalFieldCount(1);


But what would be the proper way to set the internal field count for the 
function instance itself?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] Error cross compiling V8 with is_component_build=true on ARM64

2019-02-21 Thread Darin Dimitrov
Another issue with this build but on Mac OS host:

[1/1270] SOLINK ./libc++.cr.so
FAILED: libc++.cr.so libc++.cr.so.TOC lib.unstripped/libc++.cr.so lib.
unstripped/libc++.cr.so.map.gz
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
"../../third_party/android_ndk/toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-readelf"
 
--nm=
"../../third_party/android_ndk/toolchains/x86-4.9/prebuilt/darwin-x86_64/bin/i686-linux-android-nm"
 
--strip=../../third_party/eu-strip/bin/eu-strip --sofile=
"./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --map-file 
"./lib.unstripped/libc++.cr.so.map.gz" --output="./libc++.cr.so" -- ../../
third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,--fatal-warnings 
-Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro 
-Wl,-z,defs 
-Wl,--as-needed --gcc-toolchain=../../third_party/android_ndk/toolchains/x86
-4.9/prebuilt/darwin-x86_64 -fuse-ld=lld -Wl,--icf=all -Wl,--color-diagnostics 
-Wl,--no-rosegment -Wl,--exclude-libs=libgcc.a -Wl,--exclude-libs=
libvpx_assembly_arm.a --target=i686-linux-android -m32 
-Wl,--warn-shared-textrel 
-Wl,-O2 -Wl,--gc-sections --sysroot=../../third_party/android_ndk/platforms/
android-16/arch-x86 -nostdlib -Wl,--warn-shared-textrel -Werror 
-Wl,-u_sanitizer_options_link_helper 
-L../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/libs/x86 -o 
"./lib.unstripped/libc++.cr.so" -Wl,-soname="libc++.cr.so" @
"./libc++.cr.so.rsp"
clang: error: invalid linker name in argument '-fuse-ld=lld'
[6/1270] CXX obj/src/inspector/inspector/injected-script.o
ninja: build stopped: subcommand failed.
build finished in 7 seconds

It seems that the LLD linker is not found on Mac OS. Contrary to my Ubuntu 
setup, looking at the "third_party/llvm-build/Release+Asserts/bin" folder 
there doesn't seem to exist a "lld" or "ld.lld" or "ld64.lld" files.

On Wednesday, February 20, 2019 at 3:03:58 PM UTC+2, Jakob Gruber wrote:
>
> +Michael Achenbach  
>
> On Wed, Feb 20, 2019 at 1:04 PM Darin Dimitrov  > wrote:
>
>> Yes, but there's no *libandroid_support.a* for ARM64. This file exists 
>> only for ARM and x86 in the NDKs. Also as far as I know, API levels >= 21 
>> do not need this file anymore.
>>
>> Looking at this line here: 
>> https://chromium.googlesource.com/chromium/src/build.git/+/refs/heads/master/config/android/BUILD.gn#120
>>
>> libs += [ "android_support" ]
>>
>> It looks like V8 is *always *trying to link to *libandroid_support.a*. 
>> If I put a condition there:
>>
>> if (current_cpu != "arm64") {
>> libs += [ "android_support" ]
>> }
>>
>> then everything seems to build and work fine.
>>
>> On Wednesday, February 20, 2019 at 12:20:01 PM UTC+2, Jakob Gruber wrote:
>>>
>>> You are building with target_os="android"; would you expect this to not 
>>> need libandroid_support?
>>>
>>> On Wed, Feb 20, 2019 at 10:23 AM Darin Dimitrov  
>>> wrote:
>>>
>>>> I am trying to cross compile V8 for ARM64 with 
>>>> *is_component_build=true* for ARM64:
>>>>
>>>> gn gen outgn/release --args="is_component_build=true is_debug=false 
>>>> symbol_level=0 target_cpu=\"arm64\" v8_target_cpu=\"arm64\" 
>>>> target_os=\"android\""
>>>> ninja -v -C outgn/release v8_libplatform
>>>>
>>>> And getting the following compilation error when linking libc++:
>>>>
>>>> [85/89] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
>>>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf"
>>>>  
>>>> --nm=
>>>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm"
>>>>  
>>>> --strip=../../buildtools/third_party/eu-strip/bin/eu-strip --sofile=
>>>> "./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --output
>>>> ="./libc++.cr.so" -- ../../third_party/llvm-build/Release+Asserts/bin/
>>>> clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro 
>>>> -Wl,-z,defs -Wl,--as-needed --gcc-toolchain=../../third_party/
>>>> android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 
>>>> -fuse-ld=lld -Wl,-z,max-page-size=4096 -Wl,--icf=all 
>>>> -Wl,--color-diagnostics 
>>>> -Wl,-

Re: [v8-users] Error cross compiling V8 with is_component_build=true on ARM64

2019-02-20 Thread Darin Dimitrov
Yes, but there's no *libandroid_support.a* for ARM64. This file exists only 
for ARM and x86 in the NDKs. Also as far as I know, API levels >= 21 do not 
need this file anymore.

Looking at this line 
here: 
https://chromium.googlesource.com/chromium/src/build.git/+/refs/heads/master/config/android/BUILD.gn#120

libs += [ "android_support" ]

It looks like V8 is *always *trying to link to *libandroid_support.a*. If I 
put a condition there:

if (current_cpu != "arm64") {
libs += [ "android_support" ]
}

then everything seems to build and work fine.

On Wednesday, February 20, 2019 at 12:20:01 PM UTC+2, Jakob Gruber wrote:
>
> You are building with target_os="android"; would you expect this to not 
> need libandroid_support?
>
> On Wed, Feb 20, 2019 at 10:23 AM Darin Dimitrov  > wrote:
>
>> I am trying to cross compile V8 for ARM64 with *is_component_build=true* 
>> for ARM64:
>>
>> gn gen outgn/release --args="is_component_build=true is_debug=false 
>> symbol_level=0 target_cpu=\"arm64\" v8_target_cpu=\"arm64\" 
>> target_os=\"android\""
>> ninja -v -C outgn/release v8_libplatform
>>
>> And getting the following compilation error when linking libc++:
>>
>> [85/89] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf"
>>  
>> --nm=
>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm"
>>  
>> --strip=../../buildtools/third_party/eu-strip/bin/eu-strip --sofile=
>> "./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --output=
>> "./libc++.cr.so" -- ../../third_party/llvm-build/Release+Asserts/bin/
>> clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro 
>> -Wl,-z,defs -Wl,--as-needed --gcc-toolchain=../../third_party/android_ndk
>> /toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fuse-ld=lld 
>> -Wl,-z,max-page-size=4096 -Wl,--icf=all -Wl,--color-diagnostics 
>> -Wl,--no-rosegment 
>> -Wl,--exclude-libs=libgcc.a -Wl,--exclude-libs=libvpx_assembly_arm.a --
>> target=aarch64-linux-android -Wl,--warn-shared-textrel -Wl,-O2 
>> -Wl,--gc-sections 
>> --sysroot=../../third_party/android_ndk/platforms/android-21/arch-arm64 
>> -nostdlib 
>> -Wl,--warn-shared-textrel -Werror -Wl,-u_sanitizer_options_link_helper -L
>> ../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/libs/arm64-v8a 
>> -o "./lib.unstripped/libc++.cr.so" -Wl,-soname="libc++.cr.so" @
>> "./libc++.cr.so.rsp"
>> FAILED: libc++.cr.so libc++.cr.so.TOC lib.unstripped/libc++.cr.so
>> python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf"
>>  
>> --nm=
>> "../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm"
>>  
>> --strip=../../buildtools/third_party/eu-strip/bin/eu-strip --sofile=
>> "./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --output=
>> "./libc++.cr.so" -- ../../third_party/llvm-build/Release+Asserts/bin/
>> clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro 
>> -Wl,-z,defs -Wl,--as-needed --gcc-toolchain=../../third_party/android_ndk
>> /toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fuse-ld=lld 
>> -Wl,-z,max-page-size=4096 -Wl,--icf=all -Wl,--color-diagnostics 
>> -Wl,--no-rosegment 
>> -Wl,--exclude-libs=libgcc.a -Wl,--exclude-libs=libvpx_assembly_arm.a --
>> target=aarch64-linux-android -Wl,--warn-shared-textrel -Wl,-O2 
>> -Wl,--gc-sections 
>> --sysroot=../../third_party/android_ndk/platforms/android-21/arch-arm64 
>> -nostdlib 
>> -Wl,--warn-shared-textrel -Werror -Wl,-u_sanitizer_options_link_helper -L
>> ../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/libs/arm64-v8a 
>> -o "./lib.unstripped/libc++.cr.so" -Wl,-soname="libc++.cr.so" @
>> "./libc++.cr.so.rsp"
>> ld.lld: error: unable to find library -landroid_support
>>
>> So the question is why is the linker trying to find *libandroid_supprt* 
>> for ARM64 builds and how to fix this error?
>>
>>
>>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Different object files generated when cross compiling V8 7.3 for Android ARM (vs V8 7.2)

2019-02-20 Thread Darin Dimitrov
Turns out that V8 is building against a custom STL passing 
the _LIBCPP_ABI_UNSTABLE flag. So in order to build my final executable I 
had to use this same STL instead of the default libc++_static.a library 
provided by the NDK.

On Wednesday, February 13, 2019 at 9:24:34 AM UTC+2, Darin Dimitrov wrote:
>
> Tom, thanks for the reply. The DefaultPlatform method was just an example. 
> Looking at the public API in v8.h 
> <https://github.com/v8/v8/blob/master/include/v8.h> there are quite a lot 
> of references to C++ objects from the standard library and I am getting 
> tons of those similar linker errors. That's what made me think that I must 
> be doing something wrong.
>
> I managed to successfully compile and link if I manually modify 
> _LIBCPP_ABI_NAMESPACE in the "third_party/libc++/trunk/include/__config" 
> include file. But I feel that it should somehow be possible to specify the 
> libc++ location when building v8 so that it uses the one from the NDK.
>
> On Tuesday, February 12, 2019 at 10:15:04 PM UTC+2, Tom Anderson wrote:
>>
>> Usually C++ objects should not be passed over library boundaries.  In 
>> this case though, the issue could be fixed by adding a wrapper for 
>> v8::platform::DefaultPlatform::DefaultPlatform() that takes a C-style 
>> pointer instead of a unique_ptr.
>>
>> I'm also not sure if v8_libplatform is meant to be redistributed in this 
>> way, though the V8 team can say for sure.
>>
>> On Tuesday, February 12, 2019 at 8:05:19 AM UTC-8, Darin Dimitrov wrote:
>>>
>>> Further narrowing this down.
>>>
>>> In V8 *7.2*, libc++ is taken from the NDK: 
>>>
>>> -isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/
>>> include
>>> -isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++abi/
>>> include
>>>
>>> whereas in V8 *7.3*, a different libc++ is used:
>>>
>>> -isystem../../buildtools/third_party/libc++/trunk/include
>>> -isystem../../buildtools/third_party/libc++abi/trunk/include
>>>
>>> And the difference between the two versions is that the one from the NDK 
>>> defines the following std namespace override:
>>>
>>> #ifndef _LIBCPP_ABI_NAMESPACE
>>> # define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__ndk,_LIBCPP_ABI_VERSION)
>>> #endif
>>>
>>> while the custom one uses this:
>>>
>>> #ifndef _LIBCPP_ABI_NAMESPACE
>>> # define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
>>> #endif
>>>
>>> So the question is, what would be the proper gn arguments to link 
>>> against libc++ from the NDK?
>>>
>>> I have tried setting use_custom_libcxx=false but in this case no 
>>> -isystem is specified and the build fails as it cannot find some common 
>>> includes such as  and .
>>>
>>> On Monday, February 11, 2019 at 6:09:49 PM UTC+2, Darin Dimitrov wrote:
>>>>
>>>> I was able to bisect the issue to the following commit in which the V8 
>>>> DEPS were updated: 
>>>> https://chromium.googlesource.com/v8/v8/+/843535b893968a89f98b295cd7b1b265ca2927c1
>>>>
>>>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Error cross compiling V8 with is_component_build=true on ARM64

2019-02-20 Thread Darin Dimitrov
I am trying to cross compile V8 for ARM64 with *is_component_build=true* 
for ARM64:

gn gen outgn/release --args="is_component_build=true is_debug=false 
symbol_level=0 target_cpu=\"arm64\" v8_target_cpu=\"arm64\" 
target_os=\"android\""
ninja -v -C outgn/release v8_libplatform

And getting the following compilation error when linking libc++:

[85/89] python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
"../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf"
 
--nm=
"../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm"
 
--strip=../../buildtools/third_party/eu-strip/bin/eu-strip --sofile=
"./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --output=
"./libc++.cr.so" -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ 
-shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,defs 
-Wl,--as-needed --gcc-toolchain=../../third_party/android_ndk/toolchains/
aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fuse-ld=lld -Wl,-z,max-page
-size=4096 -Wl,--icf=all -Wl,--color-diagnostics -Wl,--no-rosegment -Wl,--
exclude-libs=libgcc.a -Wl,--exclude-libs=libvpx_assembly_arm.a --target=
aarch64-linux-android -Wl,--warn-shared-textrel -Wl,-O2 -Wl,--gc-sections --
sysroot=../../third_party/android_ndk/platforms/android-21/arch-arm64 -nostdlib 
-Wl,--warn-shared-textrel -Werror -Wl,-u_sanitizer_options_link_helper -L
../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -o 
"./lib.unstripped/libc++.cr.so" -Wl,-soname="libc++.cr.so" @
"./libc++.cr.so.rsp"
FAILED: libc++.cr.so libc++.cr.so.TOC lib.unstripped/libc++.cr.so
python "../../build/toolchain/gcc_solink_wrapper.py" --readelf=
"../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf"
 
--nm=
"../../third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm"
 
--strip=../../buildtools/third_party/eu-strip/bin/eu-strip --sofile=
"./lib.unstripped/libc++.cr.so" --tocfile="./libc++.cr.so.TOC" --output=
"./libc++.cr.so" -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ 
-shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,defs 
-Wl,--as-needed --gcc-toolchain=../../third_party/android_ndk/toolchains/
aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fuse-ld=lld -Wl,-z,max-page
-size=4096 -Wl,--icf=all -Wl,--color-diagnostics -Wl,--no-rosegment -Wl,--
exclude-libs=libgcc.a -Wl,--exclude-libs=libvpx_assembly_arm.a --target=
aarch64-linux-android -Wl,--warn-shared-textrel -Wl,-O2 -Wl,--gc-sections --
sysroot=../../third_party/android_ndk/platforms/android-21/arch-arm64 -nostdlib 
-Wl,--warn-shared-textrel -Werror -Wl,-u_sanitizer_options_link_helper -L
../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -o 
"./lib.unstripped/libc++.cr.so" -Wl,-soname="libc++.cr.so" @
"./libc++.cr.so.rsp"
ld.lld: error: unable to find library -landroid_support

So the question is why is the linker trying to find *libandroid_supprt* for 
ARM64 builds and how to fix this error?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Different object files generated when cross compiling V8 7.3 for Android ARM (vs V8 7.2)

2019-02-12 Thread Darin Dimitrov
Tom, thanks for the reply. The DefaultPlatform method was just an example. 
Looking at the public API in v8.h 
<https://github.com/v8/v8/blob/master/include/v8.h> there are quite a lot 
of references to C++ objects from the standard library and I am getting 
tons of those similar linker errors. That's what made me think that I must 
be doing something wrong.

I managed to successfully compile and link if I manually modify 
_LIBCPP_ABI_NAMESPACE in the "third_party/libc++/trunk/include/__config" 
include file. But I feel that it should somehow be possible to specify the 
libc++ location when building v8 so that it uses the one from the NDK.

On Tuesday, February 12, 2019 at 10:15:04 PM UTC+2, Tom Anderson wrote:
>
> Usually C++ objects should not be passed over library boundaries.  In this 
> case though, the issue could be fixed by adding a wrapper for 
> v8::platform::DefaultPlatform::DefaultPlatform() that takes a C-style 
> pointer instead of a unique_ptr.
>
> I'm also not sure if v8_libplatform is meant to be redistributed in this 
> way, though the V8 team can say for sure.
>
> On Tuesday, February 12, 2019 at 8:05:19 AM UTC-8, Darin Dimitrov wrote:
>>
>> Further narrowing this down.
>>
>> In V8 *7.2*, libc++ is taken from the NDK: 
>>
>> -isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/include
>> -isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++abi/
>> include
>>
>> whereas in V8 *7.3*, a different libc++ is used:
>>
>> -isystem../../buildtools/third_party/libc++/trunk/include
>> -isystem../../buildtools/third_party/libc++abi/trunk/include
>>
>> And the difference between the two versions is that the one from the NDK 
>> defines the following std namespace override:
>>
>> #ifndef _LIBCPP_ABI_NAMESPACE
>> # define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__ndk,_LIBCPP_ABI_VERSION)
>> #endif
>>
>> while the custom one uses this:
>>
>> #ifndef _LIBCPP_ABI_NAMESPACE
>> # define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
>> #endif
>>
>> So the question is, what would be the proper gn arguments to link against 
>> libc++ from the NDK?
>>
>> I have tried setting use_custom_libcxx=false but in this case no -isystem 
>> is specified and the build fails as it cannot find some common includes 
>> such as  and .
>>
>> On Monday, February 11, 2019 at 6:09:49 PM UTC+2, Darin Dimitrov wrote:
>>>
>>> I was able to bisect the issue to the following commit in which the V8 
>>> DEPS were updated: 
>>> https://chromium.googlesource.com/v8/v8/+/843535b893968a89f98b295cd7b1b265ca2927c1
>>>
>>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Different object files generated when cross compiling V8 7.3 for Android ARM (vs V8 7.2)

2019-02-12 Thread Darin Dimitrov
Further narrowing this down.

In V8 *7.2*, libc++ is taken from the NDK: 

-isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++/include
-isystem../../third_party/android_ndk/sources/cxx-stl/llvm-libc++abi/include

whereas in V8 *7.3*, a different libc++ is used:

-isystem../../buildtools/third_party/libc++/trunk/include
-isystem../../buildtools/third_party/libc++abi/trunk/include

And the difference between the two versions is that the one from the NDK 
defines the following std namespace override:

#ifndef _LIBCPP_ABI_NAMESPACE
# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__ndk,_LIBCPP_ABI_VERSION)
#endif

while the custom one uses this:

#ifndef _LIBCPP_ABI_NAMESPACE
# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
#endif

So the question is, what would be the proper gn arguments to link against 
libc++ from the NDK?

I have tried setting use_custom_libcxx=false but in this case no -isystem 
is specified and the build fails as it cannot find some common includes 
such as  and .

On Monday, February 11, 2019 at 6:09:49 PM UTC+2, Darin Dimitrov wrote:
>
> I was able to bisect the issue to the following commit in which the V8 
> DEPS were updated: 
> https://chromium.googlesource.com/v8/v8/+/843535b893968a89f98b295cd7b1b265ca2927c1
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Different object files generated when cross compiling V8 7.3 for Android ARM (vs V8 7.2)

2019-02-11 Thread Darin Dimitrov
I was able to bisect the issue to the following commit in which the V8 DEPS 
were 
updated: 
https://chromium.googlesource.com/v8/v8/+/843535b893968a89f98b295cd7b1b265ca2927c1

On Monday, February 11, 2019 at 3:13:59 PM UTC+2, Darin Dimitrov wrote:
>
> I am trying to cross compile V8 for Android (ARM) on an Ubuntu host using 
> the latest NDK 19:
>
> gn gen outgn/arm-release --args="is_debug=false symbol_level=0 
> target_cpu=\"arm\" v8_target_cpu=\"arm\" target_os=\"android\""
>
> ninja -C outgn/arm-release v8_libplatform
>
> And then I try to inspect the exported symbols from the resulting object 
> file:
>
> nm -C outgn/arm-release/obj/v8_libplatform/default-platform.o | grep 
> "v8::platform::DefaultPlatform::DefaultPlatform"
>
> outputs the following when building V8 7.2.502.25:
>
> 0001 T v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::
> IdleTaskSupport, std::__ndk1::unique_ptr __ndk1::default_delete >)
>
> and the following when building V8 7.3.492.10:
>
> 0001 T v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::
> IdleTaskSupport, std::__1::unique_ptr default_delete >)
>
> Notice the "std::__ndk1" vs "std::__1". It looks like some different STL 
> is used in 7.3.
>
> As a result I am getting errors when I try to link against 
> "libv8_libplatform.a" in Android studio:
>
> error: undefined reference to 
> 'v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::IdleTaskSupport,
>  
> std::__ndk1::unique_ptr std::__ndk1::default_delete >)'
>
> Do you know what might have changed in the compilation process of V8 
> between those two versions that would result in such behavior? And is it 
> possible to somehow control this using some build flags?
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Different object files generated when cross compiling V8 7.3 for Android ARM (vs V8 7.2)

2019-02-11 Thread Darin Dimitrov
I am trying to cross compile V8 for Android (ARM) on an Ubuntu host using 
the latest NDK 19:

gn gen outgn/arm-release --args="is_debug=false symbol_level=0 
target_cpu=\"arm\" v8_target_cpu=\"arm\" target_os=\"android\""

ninja -C outgn/arm-release v8_libplatform

And then I try to inspect the exported symbols from the resulting object 
file:

nm -C outgn/arm-release/obj/v8_libplatform/default-platform.o | grep 
"v8::platform::DefaultPlatform::DefaultPlatform"

outputs the following when building V8 7.2.502.25:

0001 T v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::
IdleTaskSupport, std::__ndk1::unique_ptr >)

and the following when building V8 7.3.492.10:

0001 T v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::
IdleTaskSupport, std::__1::unique_ptr >)

Notice the "std::__ndk1" vs "std::__1". It looks like some different STL is 
used in 7.3.

As a result I am getting errors when I try to link against 
"libv8_libplatform.a" in Android studio:

error: undefined reference to 
'v8::platform::DefaultPlatform::DefaultPlatform(v8::platform::IdleTaskSupport, 
std::__ndk1::unique_ptr >)'

Do you know what might have changed in the compilation process of V8 
between those two versions that would result in such behavior? And is it 
possible to somehow control this using some build flags?

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] mksnapshot creates invalid embedded.S on MacOS

2019-02-06 Thread Darin Dimitrov
Thanks Jakob, filed a bug: 
https://bugs.chromium.org/p/v8/issues/detail?id=8795

On Wednesday, February 6, 2019 at 5:57:00 PM UTC+2, Jakob Gruber wrote:
>
> This 
> <https://cs.chromium.org/chromium/src/v8/src/snapshot/embedded-file-writer.cc?l=135=07a4ab041b9731c3feb6c247f74f0920863b28be>
>  is 
> where the _ prefixes are generated. Specifically, mksnapshot generates an 
> embedded.S file based on the host OS, which is incorrect for 
> cross-compilation. A similar issue came up for OSX-to-Fuchsia 
> cross-compiles, see https://crrev.com/c/1377230 for the fix. Something 
> similar should also work for you. 
>
> As a more general solution we should dispatch based on the target (instead 
> of host) OS / architecture in this entire file. Could you file a bug? I'm 
> also happy to accept patches for this.
>
> On Wed, Feb 6, 2019 at 4:35 PM Darin Dimitrov  > wrote:
>
>> I am trying to cross-compile V8 for ARM on MacOS. At some point of the 
>> compilation process, mksnapshot is used to create the snapshot_blob.bin 
>> file:
>>
>> python ../../tools/run.py ./clang_x86_v8_arm/mksnapshot 
>> --turbo_instruction_scheduling 
>> --embedded_src gen/embedded.S --embedded_variant Default --random-seed 
>> 314159265 --startup_blob snapshot_blob.bin
>>
>> The resulting embedded.S seems invalid because all label names are 
>> prefixed with _
>>
>> .text
>> .balign 32
>> _v8_Default_embedded_blob_data_:
>>   .octa 0x320030c00d96c5c,0x3a0003803600038
>>   
>> _Builtins_AdaptorWithExitFrame:
>>   .octa 0xe24dd004e1a04080e285e591700f,
>> 0xee0eca10e51acfc3e52d3004e92d0012
>>   ...
>> _Builtins_AdaptorWithBuiltinExitFrame:
>>   .octa 0xe24dd004e1a04080e285e591700f,
>> 0xee0eca10e51acfc3e52d3004e92d0012
>>   ...
>> _Builtins_ArgumentsAdaptorTrampoline:
>>   .octa 0xe1520a34e152000ce30fcfff,
>> 0xe92d4813e3a04024e080ba12
>>   ...
>>
>>
>>
>> As a result, a compilation error is emitted:
>>
>> FAILED: obj/v8_external_snapshot/embedded.o
>>
>> ../../third_party/llvm-build/Release+Asserts/bin/clang -MMD -MF obj/
>> v8_external_snapshot/embedded.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC 
>> -DSAFE_BROWSING_DB_REMOTE -DOFFICIAL_BUILD -DCHROMIUM_BUILD 
>> -DFIELDTRIAL_TESTING_ENABLED 
>> -D_GNU_SOURCE -DANDROID -DHAVE_SYS_UIO_H -DANDROID_NDK_VERSION_ROLL=r16_1 
>> -DCR_CLANG_REVISION=\"346388-5\" -D__STDC_CONSTANT_MACROS 
>> -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D__GNU_SOURCE=1 
>> -DCHROMIUM_CXX_TWEAK_INLINES -DNDEBUG -DNVALGRIND 
>> -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 
>> -DENABLE_MINOR_MC -DV8_DEPRECATION_WARNINGS 
>> -DV8_IMMINENT_DEPRECATION_WARNINGS -DV8_USE_SNAPSHOT 
>> -DV8_USE_EXTERNAL_STARTUP_DATA -DV8_CONCURRENT_MARKING 
>> -DV8_EMBEDDED_BUILTINS -DV8_TARGET_ARCH_ARM -DCAN_USE_ARMV7_INSTRUCTIONS 
>> -DCAN_USE_VFP3_INSTRUCTIONS -DCAN_USE_VFP32DREGS -DCAN_USE_NEON -I../.. 
>> -Igen -I../.. -Igen -fPIC -fno-strict-aliasing --param=ssp-buffer-size=4 
>> -fstack-protector -funwind-tables -fPIC -fcolor-diagnostics 
>> -fmerge-all-constants -Xclang -mllvm -Xclang 
>> -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -std=c11 
>> -ffunction-sections -fno-short-enums --target=arm-linux-androideabi 
>> -isystem../../third_party/android_ndk/sysroot/usr/include/arm-linux-androideabi
>>  
>> -D__ANDROID_API__=16 -DHAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC=1 
>> -march=armv7-a -mfloat-abi=softfp -mtune=generic-armv7-a -mfpu=neon -g0 
>> --sysroot=../../third_party/android_ndk/sysroot -c gen/embedded.S -o 
>> obj/v8_external_snapshot/embedded.o
>> gen/embedded.S:41481:17: error: unable to emit symbol attribute in 
>> directive
>> .private_extern _v8_Default_embedded_blob_
>> ^
>> gen/embedded.S:41486:1: error: unknown directive
>> .const_data
>> ^
>> gen/embedded.S:41487:17: error: unable to emit symbol attribute in 
>> directive
>> .private_extern _v8_Default_embedded_blob_size_
>> ^
>> ninja: build stopped: subcommand failed.
>>
>>
>>
>> The same process works fine on Ubuntu where the embedded.S labels are not 
>> prefixed with underscores.
>>
>> Do you have any idea where this difference in the generated embedded.S 
>> might come from?
>>
>> NOTE: I am building from the 7.2.502.24 tag.
>>
>>
>>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] mksnapshot creates invalid embedded.S on MacOS

2019-02-06 Thread Darin Dimitrov
I am trying to cross-compile V8 for ARM on MacOS. At some point of the 
compilation process, mksnapshot is used to create the snapshot_blob.bin 
file:

python ../../tools/run.py ./clang_x86_v8_arm/mksnapshot 
--turbo_instruction_scheduling 
--embedded_src gen/embedded.S --embedded_variant Default --random-seed 
314159265 --startup_blob snapshot_blob.bin

The resulting embedded.S seems invalid because all label names are prefixed 
with _

.text
.balign 32
_v8_Default_embedded_blob_data_:
  .octa 0x320030c00d96c5c,0x3a0003803600038
  
_Builtins_AdaptorWithExitFrame:
  .octa 0xe24dd004e1a04080e285e591700f,
0xee0eca10e51acfc3e52d3004e92d0012
  ...
_Builtins_AdaptorWithBuiltinExitFrame:
  .octa 0xe24dd004e1a04080e285e591700f,
0xee0eca10e51acfc3e52d3004e92d0012
  ...
_Builtins_ArgumentsAdaptorTrampoline:
  .octa 0xe1520a34e152000ce30fcfff,
0xe92d4813e3a04024e080ba12
  ...



As a result, a compilation error is emitted:

FAILED: obj/v8_external_snapshot/embedded.o

../../third_party/llvm-build/Release+Asserts/bin/clang -MMD -MF obj/
v8_external_snapshot/embedded.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC 
-DSAFE_BROWSING_DB_REMOTE 
-DOFFICIAL_BUILD -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_GNU_SOURCE 
-DANDROID -DHAVE_SYS_UIO_H -DANDROID_NDK_VERSION_ROLL=r16_1 -
DCR_CLANG_REVISION=\"346388-5\" -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D__GNU_SOURCE=1 
-DCHROMIUM_CXX_TWEAK_INLINES -DNDEBUG -DNVALGRIND 
-DDYNAMIC_ANNOTATIONS_ENABLED=0 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 
-DENABLE_MINOR_MC -DV8_DEPRECATION_WARNINGS 
-DV8_IMMINENT_DEPRECATION_WARNINGS -DV8_USE_SNAPSHOT 
-DV8_USE_EXTERNAL_STARTUP_DATA -DV8_CONCURRENT_MARKING 
-DV8_EMBEDDED_BUILTINS -DV8_TARGET_ARCH_ARM -DCAN_USE_ARMV7_INSTRUCTIONS 
-DCAN_USE_VFP3_INSTRUCTIONS -DCAN_USE_VFP32DREGS -DCAN_USE_NEON -I../.. 
-Igen -I../.. -Igen -fPIC -fno-strict-aliasing --param=ssp-buffer-size=4 
-fstack-protector -funwind-tables -fPIC -fcolor-diagnostics 
-fmerge-all-constants -Xclang -mllvm -Xclang 
-instcombine-lower-dbg-declare=0 -no-canonical-prefixes -std=c11 
-ffunction-sections -fno-short-enums --target=arm-linux-androideabi 
-isystem../../third_party/android_ndk/sysroot/usr/include/arm-linux-androideabi 
-D__ANDROID_API__=16 -DHAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC=1 
-march=armv7-a -mfloat-abi=softfp -mtune=generic-armv7-a -mfpu=neon -g0 
--sysroot=../../third_party/android_ndk/sysroot -c gen/embedded.S -o 
obj/v8_external_snapshot/embedded.o
gen/embedded.S:41481:17: error: unable to emit symbol attribute in directive
.private_extern _v8_Default_embedded_blob_
^
gen/embedded.S:41486:1: error: unknown directive
.const_data
^
gen/embedded.S:41487:17: error: unable to emit symbol attribute in directive
.private_extern _v8_Default_embedded_blob_size_
^
ninja: build stopped: subcommand failed.



The same process works fine on Ubuntu where the embedded.S labels are not 
prefixed with underscores.

Do you have any idea where this difference in the generated embedded.S 
might come from?

NOTE: I am building from the 7.2.502.24 tag.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Heap snapshot crash on ARM in V8 7.1.302.28

2018-12-10 Thread Darin Dimitrov
Strangely enough, if I create a large number of strings just after creating 
the isolate, everything works fine:

for (int i = 0; i < 70; i++) {
v8::String::NewFromUtf8(isolate, "aaa");
}




On Wednesday, December 5, 2018 at 6:46:41 PM UTC+2, Darin Dimitrov wrote:
>
> Hello,
>
> We are embedding v8 in android on an ARM device and trying to load a heap 
> snapshot generated with the mksnapshot utility:
>
> ./outgn/arm-release/clang_x86_v8_arm/mksnapshot ./test.js --startup_blob 
> ./snapshot.blob --profile_deserialization
>
> And we are getting the following crash at runtime:
>
> SIGSEGV (signal SIGSEGV: address access protected (fault address: 
> 0x34ff4d81))
>
>
> v8::internal::SafepointEntry::HasRegisters() const 0xa148f03a
> v8::internal::StandardFrame::IterateCompiledFrame(v8::internal::
> RootVisitor*) const 0xa130a394
> v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::
> ThreadLocalTop*) 0xa1342510
> v8::internal::Heap::IterateStrongRoots(v8::internal::RootVisitor*, v8::
> internal::VisitMode) 0xa131c132
> v8::internal::MarkCompactCollector::MarkRoots(v8::internal::RootVisitor*, 
> v8::internal::ObjectVisitor*) 0xa1384ade
> v8::internal::MarkCompactCollector::MarkLiveObjects() 0xa1382c7a
> v8::internal::MarkCompactCollector::CollectGarbage() 0xa13828e0
> v8::internal::Heap::MarkCompact() 0xa1317ffe
> v8::internal::Heap::PerformGarbageCollection(v8::internal::
> GarbageCollector, v8::GCCallbackFlags) 0xa13169e6
> v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::
> internal::GarbageCollectionReason, v8::GCCallbackFlags) 0xa13159b2
> v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::
> AllocationSpace, v8::internal::AllocationAlignment) 0xa131cfca
> v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::
> AllocationSpace, v8::internal::AllocationAlignment) 0xa131d018
> v8::internal::Factory::NewFeedbackVector(v8::internal::Handle ::SharedFunctionInfo>, v8::internal::PretenureFlag) 0xa12f4ccc
> v8::internal::FeedbackVector::New(v8::internal::Isolate*, v8::internal::
> Handle) 0xa1303564
> v8::internal::JSFunction::EnsureFeedbackVector(v8::internal::Handle internal::JSFunction>) 0xa13d4862
> v8::internal::Compiler::Compile(v8::internal::Handle JSFunction>, v8::internal::Compiler::ClearExceptionFlag) 
> 0xa12965d2
> v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::
> internal::Isolate*) 0xa16d9f16
> Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit 
> 0xa17c9db0
> Builtins_CompileLazy 0xa17288fc
>  0x4658d4b8
>  0x4658d4b8
>  0x4658d4b8
>  0x4658d4b8
> Builtins_JSEntryTrampoline 0xa1725668
>  0x46586d54
>
> Unfortunately this stacktrace doesn't originate from our code which makes 
> it very hard to debug. This error only happens with V8 7.1.302.28, the 
> snapshot worked pretty smooth in 6.9.427.23.
>
> Do you have any idea what might be causing this crash or any pointers that 
> could help us further diagnose it?
>
> Note: V8 is compiled with the following flags:
>
> gn gen outgn/arm-release --args="v8_use_snapshot=true 
> v8_use_external_startup_data=false is_official_build=true is_debug=false 
> symbol_level=0 use_thin_lto=false target_cpu=\"arm\" v8_target_cpu=\"arm\" 
> v8_enable_i18n_support=false target_os=\"android\" 
> v8_android_log_stdout=false"
>
> ninja -C outgn/arm-release v8_base v8_libplatform v8_libbase 
> v8_libsampler v8_snapshot v8_initializers v8_init inspector
>
>
>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Re: Heap snapshot crash on ARM in V8 7.1.302.28

2018-12-10 Thread Darin Dimitrov
[0xf705b2d2]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x474bf8) 
[0xf702abf8]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x5dc788) 
[0xf7192788]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x5d985d) 
[0xf718f85d]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x5d94e3) 
[0xf718f4e3]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x5d62da) 
[0xf718c2da]

/home/ubuntu/v8-7/v8/outgn/arm-release/clang_x86_v8_arm/mksnapshot(+0x3ed7e) 
[0xf6bf4d7e]
Illegal instruction (core dumped)


Thanks again for looking into this,
Darin.

On Wednesday, December 5, 2018 at 6:46:41 PM UTC+2, Darin Dimitrov wrote:
>
> Hello,
>
> We are embedding v8 in android on an ARM device and trying to load a heap 
> snapshot generated with the mksnapshot utility:
>
> ./outgn/arm-release/clang_x86_v8_arm/mksnapshot ./test.js --startup_blob 
> ./snapshot.blob --profile_deserialization
>
> And we are getting the following crash at runtime:
>
> SIGSEGV (signal SIGSEGV: address access protected (fault address: 
> 0x34ff4d81))
>
>
> v8::internal::SafepointEntry::HasRegisters() const 0xa148f03a
> v8::internal::StandardFrame::IterateCompiledFrame(v8::internal::
> RootVisitor*) const 0xa130a394
> v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::
> ThreadLocalTop*) 0xa1342510
> v8::internal::Heap::IterateStrongRoots(v8::internal::RootVisitor*, v8::
> internal::VisitMode) 0xa131c132
> v8::internal::MarkCompactCollector::MarkRoots(v8::internal::RootVisitor*, 
> v8::internal::ObjectVisitor*) 0xa1384ade
> v8::internal::MarkCompactCollector::MarkLiveObjects() 0xa1382c7a
> v8::internal::MarkCompactCollector::CollectGarbage() 0xa13828e0
> v8::internal::Heap::MarkCompact() 0xa1317ffe
> v8::internal::Heap::PerformGarbageCollection(v8::internal::
> GarbageCollector, v8::GCCallbackFlags) 0xa13169e6
> v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::
> internal::GarbageCollectionReason, v8::GCCallbackFlags) 0xa13159b2
> v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::
> AllocationSpace, v8::internal::AllocationAlignment) 0xa131cfca
> v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::
> AllocationSpace, v8::internal::AllocationAlignment) 0xa131d018
> v8::internal::Factory::NewFeedbackVector(v8::internal::Handle ::SharedFunctionInfo>, v8::internal::PretenureFlag) 0xa12f4ccc
> v8::internal::FeedbackVector::New(v8::internal::Isolate*, v8::internal::
> Handle) 0xa1303564
> v8::internal::JSFunction::EnsureFeedbackVector(v8::internal::Handle internal::JSFunction>) 0xa13d4862
> v8::internal::Compiler::Compile(v8::internal::Handle JSFunction>, v8::internal::Compiler::ClearExceptionFlag) 
> 0xa12965d2
> v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::
> internal::Isolate*) 0xa16d9f16
> Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit 
> 0xa17c9db0
> Builtins_CompileLazy 0xa17288fc
>  0x4658d4b8
>  0x4658d4b8
>  0x4658d4b8
>  0x4658d4b8
> Builtins_JSEntryTrampoline 0xa1725668
>  0x46586d54
>
> Unfortunately this stacktrace doesn't originate from our code which makes 
> it very hard to debug. This error only happens with V8 7.1.302.28, the 
> snapshot worked pretty smooth in 6.9.427.23.
>
> Do you have any idea what might be causing this crash or any pointers that 
> could help us further diagnose it?
>
> Note: V8 is compiled with the following flags:
>
> gn gen outgn/arm-release --args="v8_use_snapshot=true 
> v8_use_external_startup_data=false is_official_build=true is_debug=false 
> symbol_level=0 use_thin_lto=false target_cpu=\"arm\" v8_target_cpu=\"arm\" 
> v8_enable_i18n_support=false target_os=\"android\" 
> v8_android_log_stdout=false"
>
> ninja -C outgn/arm-release v8_base v8_libplatform v8_libbase 
> v8_libsampler v8_snapshot v8_initializers v8_init inspector
>
>
>
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Heap snapshot crash on ARM in V8 7.1.302.28

2018-12-05 Thread Darin Dimitrov
Hello,

We are embedding v8 in android on an ARM device and trying to load a heap 
snapshot generated with the mksnapshot utility:

./outgn/arm-release/clang_x86_v8_arm/mksnapshot ./test.js --startup_blob ./
snapshot.blob --profile_deserialization

And we are getting the following crash at runtime:

SIGSEGV (signal SIGSEGV: address access protected (fault address: 0x34ff4d81
))


v8::internal::SafepointEntry::HasRegisters() const 0xa148f03a
v8::internal::StandardFrame::IterateCompiledFrame(v8::internal::RootVisitor
*) const 0xa130a394
v8::internal::Isolate::Iterate(v8::internal::RootVisitor*, v8::internal::
ThreadLocalTop*) 0xa1342510
v8::internal::Heap::IterateStrongRoots(v8::internal::RootVisitor*, v8::
internal::VisitMode) 0xa131c132
v8::internal::MarkCompactCollector::MarkRoots(v8::internal::RootVisitor*, v8
::internal::ObjectVisitor*) 0xa1384ade
v8::internal::MarkCompactCollector::MarkLiveObjects() 0xa1382c7a
v8::internal::MarkCompactCollector::CollectGarbage() 0xa13828e0
v8::internal::Heap::MarkCompact() 0xa1317ffe
v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, 
v8::GCCallbackFlags) 0xa13169e6
v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::
internal::GarbageCollectionReason, v8::GCCallbackFlags) 0xa13159b2
v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::
AllocationSpace, v8::internal::AllocationAlignment) 0xa131cfca
v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::
AllocationSpace, v8::internal::AllocationAlignment) 0xa131d018
v8::internal::Factory::NewFeedbackVector(v8::internal::Handle, v8::internal::PretenureFlag) 0xa12f4ccc
v8::internal::FeedbackVector::New(v8::internal::Isolate*, v8::internal::
Handle) 0xa1303564
v8::internal::JSFunction::EnsureFeedbackVector(v8::internal::Handle) 0xa13d4862
v8::internal::Compiler::Compile(v8::internal::Handle, v8::internal::Compiler::ClearExceptionFlag) 0xa12965d2
v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::internal
::Isolate*) 0xa16d9f16
Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit 
0xa17c9db0
Builtins_CompileLazy 0xa17288fc
 0x4658d4b8
 0x4658d4b8
 0x4658d4b8
 0x4658d4b8
Builtins_JSEntryTrampoline 0xa1725668
 0x46586d54

Unfortunately this stacktrace doesn't originate from our code which makes 
it very hard to debug. This error only happens with V8 7.1.302.28, the 
snapshot worked pretty smooth in 6.9.427.23.

Do you have any idea what might be causing this crash or any pointers that 
could help us further diagnose it?

Note: V8 is compiled with the following flags:

gn gen outgn/arm-release --args="v8_use_snapshot=true 
v8_use_external_startup_data=false is_official_build=true is_debug=false 
symbol_level=0 use_thin_lto=false target_cpu=\"arm\" v8_target_cpu=\"arm\" 
v8_enable_i18n_support=false target_os=\"android\" 
v8_android_log_stdout=false"

ninja -C outgn/arm-release v8_base v8_libplatform v8_libbase v8_libsampler 
v8_snapshot v8_initializers v8_init inspector



-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[v8-users] Cross compiling V8 7.0.276.27 for android

2018-10-19 Thread Darin Dimitrov
I am trying to cross compile V8 7.0.276.27 for android targeting arm64.

I have used the following arguments:

gn gen out/arm64.release --args='is_official_build=true is_debug=false 
symbol_level=0 v8_use_snapshot=true v8_use_external_startup_data=false 
target_cpu="arm64" v8_target_cpu="arm64" v8_enable_i18n_support=false 
target_os="android" v8_android_log_stdout=true'

and this command to build:

ninja -C out/arm64.release v8_base v8_libplatform v8_libbase v8_libsampler 
v8_snapshot v8_initializers v8_init inspector

Using those arguments, the generated object files contain "LLVM IR bitcode" 
and are not compiled to native arm64.

In V8 6.9.427.23 those same arguments were producing "ELF 64-bit LSB  
relocatable, ARM aarch64, version 1 (SYSV), not stripped" object files.

I have noticed that if I remove the "is_official_build=true" argument then 
the expected object files are generated.

So my question is what has changed between 6.9.427.23 and 7.0.276.27 and 
what would be the correct way to generate optimized native binaries.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.