Hey, guys.I'm working on integration of some library to be used in Chromium fork (Qualcomm fork). In order to do some work i need v8 instance to be createdin main process (to be accessed in chrome_network_delegate). I'm trying to create new IsolateHolder instance and get isolate instance from it with `isolate()`.For this i have to pass SingleThreadTaskRunner instance to IsolateHolder ctor. I've tried to use `base::ThreadTaskRunnerHandle::Get()` but it crashes.I've looked into ThreadTaskRunnerHandle internals and saw it uses LAZY_INSTANCE_INITIALIZER so i expect it to be created on the first invocation.But in fact `isSet` returns `false` and Get() crashes because Pointer() is `nullptr`. Unfortunately i have no idea on what's going on.
I've found v8_test.cc but it uses `base::ThreadTaskRunnerHandle::Get()` and seems to be fine here.
Any help is highly appreciated.PS. I've tried to pass MessageLoop instance .task_runner() but it crashes for some reason later.PPS. I'm not advanced C++ developer (Java/Android)
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/93c2a055-9e0f-46bc-b1fd-53673483ae80%40chromium.org.
On Tue, Aug 22, 2017 at 10:11 AM, Anton Smirnov <d...@antonsmirnov.name> wrote:Hey, guys.I'm working on integration of some library to be used in Chromium fork (Qualcomm fork). In order to do some work i need v8 instance to be createdin main process (to be accessed in chrome_network_delegate). I'm trying to create new IsolateHolder instance and get isolate instance from it with `isolate()`.For this i have to pass SingleThreadTaskRunner instance to IsolateHolder ctor. I've tried to use `base::ThreadTaskRunnerHandle::Get()` but it crashes.I've looked into ThreadTaskRunnerHandle internals and saw it uses LAZY_INSTANCE_INITIALIZER so i expect it to be created on the first invocation.But in fact `isSet` returns `false` and Get() crashes because Pointer() is `nullptr`. Unfortunately i have no idea on what's going on.Are you sure that's the reason for the crash? Because it doesn't make any sense (a base::LazyInstance<scoped_refptr<Foo>>::Pointer() cannot return null, at worst it will return the address of a scoped_refpt<Foo> instance that points to nullptr, and Get() should just return a reference to it).
I suspect you're hitting the CHECK() inside ThreadTaskRunnerHandle::Get(), which has a rather unfortunate, as in "technically correct, but unhelpful", error message, which should appear in your log.
From what I understand of the current task/thread/scheduler/message_loop/task_runner architecture:
- Each thread in Chromium can be associated with one (and at most one) TaskRunner instance.
- ThreadTaskRunnerHandle::Get() is a convenience function used to retrieve the TaskRunner instance for the current thread,
but it will crash if you haven't set the thread-specific instance previously.
- This function is called implicitly by many other task-related
functions (e.g. base::PostTask() ends up doing so) so it is important to set this up properly early.- Normally, this thread setup is done by creating a new ThreadTaskRunnerHandle() (passing the desired TaskRunner to the constructor).
This is done automatically for you by other classes. E.g. Constructing a base::MessageLoop instance does that for you (see base::MessageLoop::BindToCurrentThread(), called by the default constructor, or by the base::Thread inner loop).
It looks like you're trying to use Chromium task-related functions in a custom program that is not Chromium itself.
If so, you will need to perform specific initialization steps:1) Create a base::MessageLoop instance in the current / main thread.2) Call base::TaskScheduler::Create() (or base::TaskScheduler::CreateAndStartWithDefaultParams()). The base::TaskScheduler is a global per-process object that must be initialized at program startup (or when a shared library that links against its own version of //base is loaded/started). Failure to do so will result in other runtime crashes (with equally cryptic error messages).3) You may also need to call base::CreateSingleThreadTaskRunner() or base::CreateSequencedTaskRunner() at some point, but that doesn't seem always necessary.
I must admit that I'm mostly confused by all this too, I had to discover it on my own recently, experimenting for something else entirely (loading a shared library with its own copy of //base linked in).I believe that most of this is still in flux (there is a huge effort to move from thread-based task processing to sequence-based one). This implies a lot of refactoring, and it is sometimes hard to understand what is part of the final design, and what is transitive and/or deprecated. Hopefully some real expert might be able to complement or correct what I just wrote.I've found v8_test.cc but it uses `base::ThreadTaskRunnerHandle::Get()` and seems to be fine here.That's because the corresponding test class instanciates a base::test::ScopedTaskEnvironment, which does all the initialization for you during unit-testing (have a look at its constructor code).
Any help is highly appreciated.PS. I've tried to pass MessageLoop instance .task_runner() but it crashes for some reason later.PPS. I'm not advanced C++ developer (Java/Android)
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Hello Anton,It looks like you have an older version of the Chromium sources, so it is hard to know exactly what's going on
(as I wrote, a lot of this code seems to be under heavy refactoring).
On the other hand, I'm pretty sure that
base::ThreadTaskRunnerHandle::Get() crashing means that you're calling it from a thread that was not
properly setup.For the record, global variables are initialized at library load-time on Android, which happens on a temporary
background thread on Android (IIRC, to allow Java initialization happening in the main thread to continue in
parallel). That may explain your issue.
I've found TashScheduler to be `nullptr` and it made me think it's not yet initialized and that was the actual reason -i've moved invocation to happen a bit later (Android Activity 'startwithNative' from 'onCreate') and TaskScheduler was not 'nullptr' andeverything start work as expected.
Now i'm having another issue - the UI is sluggish and the webpage is not actually rendered.My ideas is that something (tasks) happens on current thread (and it's UI thread) and it should be moved to background thread.Just thoughts though. As i'm creating MessageLoop with the thread and i think it can be the reason.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/6225f59b-6212-4a7c-b899-e1147fa5e6b9%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CACnJMqrxE5gQPh9sqAMeXPbeRYcfk3qBz1AXiNPh-%3D%3D7N%3DGQ8A%40mail.gmail.com.
On Tue, Aug 22, 2017 at 10:11 AM, Anton Smirnov <d...@antonsmirnov.name> wrote:Hey, guys.I'm working on integration of some library to be used in Chromium fork (Qualcomm fork). In order to do some work i need v8 instance to be createdin main process (to be accessed in chrome_network_delegate). I'm trying to create new IsolateHolder instance and get isolate instance from it with `isolate()`.For this i have to pass SingleThreadTaskRunner instance to IsolateHolder ctor. I've tried to use `base::ThreadTaskRunnerHandle::Get()` but it crashes.I've looked into ThreadTaskRunnerHandle internals and saw it uses LAZY_INSTANCE_INITIALIZER so i expect it to be created on the first invocation.But in fact `isSet` returns `false` and Get() crashes because Pointer() is `nullptr`. Unfortunately i have no idea on what's going on.Are you sure that's the reason for the crash? Because it doesn't make any sense (a base::LazyInstance<scoped_refptr<Foo>>::Pointer() cannot return null, at worst it will return the address of a scoped_refpt<Foo> instance that points to nullptr, and Get() should just return a reference to it).I suspect you're hitting the CHECK() inside ThreadTaskRunnerHandle::Get(), which has a rather unfortunate, as in "technically correct, but unhelpful", error message, which should appear in your log.From what I understand of the current task/thread/scheduler/message_loop/task_runner architecture:
- Each thread in Chromium can be associated with one (and at most one) TaskRunner instance.
- ThreadTaskRunnerHandle::Get() is a convenience function used to retrieve the TaskRunner instance for the current thread,
but it will crash if you haven't set the thread-specific instance previously. This function is called implicitly by many other task-related
functions (e.g. base::PostTask() ends up doing so) so it is important to set this up properly early.- Normally, this thread setup is done by creating a new ThreadTaskRunnerHandle() (passing the desired TaskRunner to the constructor).
This is done automatically for you by other classes. E.g. Constructing a base::MessageLoop instance does that for you (see base::MessageLoop::BindToCurrentThread(), called by the default constructor, or by the base::Thread inner loop).
It looks like you're trying to use Chromium task-related functions in a custom program that is not Chromium itself. If so, you will need to perform specific initialization steps:1) Create a base::MessageLoop instance in the current / main thread.2) Call base::TaskScheduler::Create() (or base::TaskScheduler::CreateAndStartWithDefaultParams()). The base::TaskScheduler is a global per-process object that must be initialized at program startup (or when a shared library that links against its own version of //base is loaded/started). Failure to do so will result in other runtime crashes (with equally cryptic error messages).
3) You may also need to call base::CreateSingleThreadTaskRunner() or base::CreateSequencedTaskRunner() at some point, but that doesn't seem always necessary.I must admit that I'm mostly confused by all this too, I had to discover it on my own recently, experimenting for something else entirely (loading a shared library with its own copy of //base linked in).I believe that most of this is still in flux (there is a huge effort to move from thread-based task processing to sequence-based one). This implies a lot of refactoring, and it is sometimes hard to understand what is part of the final design, and what is transitive and/or deprecated. Hopefully some real expert might be able to complement or correct what I just wrote.
I've found v8_test.cc but it uses `base::ThreadTaskRunnerHandle::Get()` and seems to be fine here.That's because the corresponding test class instanciates a base::test::ScopedTaskEnvironment, which does all the initialization for you during unit-testing (have a look at its constructor code).Any help is highly appreciated.PS. I've tried to pass MessageLoop instance .task_runner() but it crashes for some reason later.PPS. I'm not advanced C++ developer (Java/Android)--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/93c2a055-9e0f-46bc-b1fd-53673483ae80%40chromium.org.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CACnJMqos05af3%3DHGRO4g0XXtg17SL2Rrwc6b%3DZUSx5e6%2BDTN4A%40mail.gmail.com.