Simple development queries

162 views
Skip to first unread message

Deepak Subramanian

unread,
Feb 27, 2015, 12:52:18 PM2/27/15
to v8-u...@googlegroups.com
Query 1:
The v8natives.js seem to have a references to various functions created by the macros in runtime.* and these are referenced by a %(FUNCTIONName) kind of call. Is this a correct understanding ?
And what do the capital functions in the same file mean. 

Query 2:
I am looking for the best way to get the stackframe (the stackframe that is getting printed when one uses console.trace) internally in v8 to make some decisions based on which function in the stackframe created the statement. This just needs to be internal.

Query 3:
What is the standard practice when creating custom JS functions ? Lets say I want function.names to contain all the variables that can access the function, how to do this (or any simple example would suffice on custom JS functions pointing to custom c implementations)

Query 4:
What is Zone, ZoneList and what is the purpose of Hydrogen.

Thanks a lot.

Sorry to post so many queries. If you prefer a small chat over irc let me know the channel.

Best Regards,
Deepak



Deepak Subramanian

unread,
Feb 27, 2015, 12:56:59 PM2/27/15
to v8-u...@googlegroups.com
I am relatively new to v8. Please note, I would like this to run in un-modified d8 while modifying v8 only. Thanks.

Jakob Kummerow

unread,
Feb 27, 2015, 1:13:42 PM2/27/15
to v8-u...@googlegroups.com
On Fri, Feb 27, 2015 at 6:56 PM, Deepak Subramanian <subud...@gmail.com> wrote:
I am relatively new to v8. Please note, I would like this to run in un-modified d8 while modifying v8 only. Thanks.


On Friday, February 27, 2015 at 6:52:18 PM UTC+1, Deepak Subramanian wrote:
Query 1:
The v8natives.js seem to have a references to various functions created by the macros in runtime.* and these are referenced by a %(FUNCTIONName) kind of call. Is this a correct understanding ?

Yes.
 
And what do the capital functions in the same file mean. 

 
Query 2:
I am looking for the best way to get the stackframe (the stackframe that is getting printed when one uses console.trace) internally in v8 to make some decisions based on which function in the stackframe created the statement. This just needs to be internal.

 
Query 3:
What is the standard practice when creating custom JS functions ? Lets say I want function.names to contain all the variables that can access the function, how to do this (or any simple example would suffice on custom JS functions pointing to custom c implementations)

 
Query 4:
What is Zone,

 
ZoneList

A list that's allocated in the Zone.
 
and what is the purpose of Hydrogen.


Thanks a lot.

Sorry to post so many queries. If you prefer a small chat over irc let me know the channel.

Best Regards,
Deepak



--
--
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-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deepak Subramanian

unread,
Mar 18, 2015, 5:44:36 AM3/18/15
to v8-u...@googlegroups.com
Thanks a lot. These have been most helpful.

I would like to know how to disable crankshaft. (I do not want optimizations at this phase and feel full-codegen is sufficient for my needs at the moment) I just changed isolate.cc's use_crankshaft() to return false at all times. Is this the right way to do it ?

I would also like some concrete understanding of Zone. I know this is asking a lot but if you can point me to something useful, I would be very grateful.

On Friday, February 27, 2015 at 6:52:18 PM UTC+1, Deepak Subramanian wrote:

Jakob Kummerow

unread,
Mar 18, 2015, 5:55:16 AM3/18/15
to v8-u...@googlegroups.com
On Wed, Mar 18, 2015 at 10:44 AM, Deepak Subramanian <subud...@gmail.com> wrote:
Thanks a lot. These have been most helpful.

I would like to know how to disable crankshaft. (I do not want optimizations at this phase and feel full-codegen is sufficient for my needs at the moment) I just changed isolate.cc's use_crankshaft() to return false at all times. Is this the right way to do it ?

That should work. You can also turn off the flag, either --nocrankshaft at the command line or change the default in flag-definitions.h.

Depending on what you're changing (you didn't say), that might not do what you expect, though. Crankshaft is also used internally to generate stubs, and there's no way to turn that off as there is no alternative to it. (So it's possible to break crankshaft in such a way that V8 crashes on startup even with --nocrankshaft.)
 
I would also like some concrete understanding of Zone. I know this is asking a lot but if you can point me to something useful, I would be very grateful.

I already gave you the link to the code. Read it if you care about the details.
Essentially, the Zone manages the backing store for fast bump-pointer allocation of objects, and supports no deallocation of individual objects (you can only throw away the entire zone).
 

On Friday, February 27, 2015 at 6:52:18 PM UTC+1, Deepak Subramanian wrote:
Query 1:
The v8natives.js seem to have a references to various functions created by the macros in runtime.* and these are referenced by a %(FUNCTIONName) kind of call. Is this a correct understanding ?
And what do the capital functions in the same file mean. 

Query 2:
I am looking for the best way to get the stackframe (the stackframe that is getting printed when one uses console.trace) internally in v8 to make some decisions based on which function in the stackframe created the statement. This just needs to be internal.

Query 3:
What is the standard practice when creating custom JS functions ? Lets say I want function.names to contain all the variables that can access the function, how to do this (or any simple example would suffice on custom JS functions pointing to custom c implementations)

Query 4:
What is Zone, ZoneList and what is the purpose of Hydrogen.

Thanks a lot.

Sorry to post so many queries. If you prefer a small chat over irc let me know the channel.

Best Regards,
Deepak



Deepak Subramanian

unread,
Mar 19, 2015, 11:33:41 AM3/19/15
to v8-u...@googlegroups.com
Thanks again Jakob,

 > Depending on what you're changing (you didn't say), that might not do what you expect, though. Crankshaft is also used internally to generate stubs, and there's no way to turn that off as there is no alternative to it. (So it's possible to break crankshaft in such a way that V8 crashes on startup even with --nocrankshaft.)

I am working on implementing a custom Information flow control mechanism in v8. With this in regard I would need to do the following.
1. Set some metadata to a JS variable. [But this metadata should be inaccessible to the JS context and only exist in the c context.]
2. See if a function calling has the right to call this object.
3. See the stack to see if there is a function in the call stack that has a right to pass its privileges.
4. When objects are created using the JS variable with the metadata, pass (a modified version of) the metadata to this object as well.
   >>>> I need to know when the JS variable with the metadata is used to perform a conditional so as to keep that in mind (since every statement that executes within this scope happens only because that variable was used) to compute other metadata.

I can explain the structure of the metadata and what exactly it does if you are interested.

So, I was trying to do some operations using the runtime functions but they do not seem to be executing after a couple calls to the function. For example, the runtime function Runtime_NumberAdd, is not executing after the function that is adding 2 numbers is called 2+ times. Any inputs from you are very welcome ofcourse.

Deepak Subramanian

unread,
May 25, 2015, 11:08:30 AM5/25/15
to v8-u...@googlegroups.com
Hi,

I would like to know where I can re-implement the JSValue's value method.

I see the declaration as part of the objects.h file at DECL_ACCESSORS(value, Object)
where the macro is 
#define DECL_ACCESSORS(name, type)                                      \
  inline type* name() const;                                            \
  inline void set_##name(type* value,                                   \
                         WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \

But I am not able to find the implementation of either value() or set_value(). Am I missing something trivial here ?

I am just trying to change these functions in particular.

Thanks. 

Best Regards,
Deepak Subramanian

Sven Panne

unread,
May 26, 2015, 4:01:16 AM5/26/15
to v8-u...@googlegroups.com
On Mon, May 25, 2015 at 5:08 PM, Deepak Subramanian <subud...@gmail.com> wrote:
[...] But I am not able to find the implementation of either value() or set_value(). Am I missing something trivial here ?

The magic is in src/objects-inl.h, of course again behind a macro: :-}

   ACCESSORS(JSValue, value, Object, kValueOffset)

Deepak Subramanian

unread,
May 26, 2015, 11:20:42 AM5/26/15
to v8-u...@googlegroups.com
Should've guesses. The macro maze that is v8 :) 

Is there a ninja to just expand all macros ? 

Deepak Subramanian

unread,
May 28, 2015, 9:52:41 AM5/28/15
to v8-u...@googlegroups.com
Hi. I have more queries following up :) Many thanks for all your help in advance

I added another variable to JSValue..
 // Layout description. Objects.h
  static const int kValueOffset = JSObject::kHeaderSize;
  static const int kSecretValueOffset = kValueOffset + kPointerSize; //NEWLINE
  static const int kSize = kSecretValueOffset + kPointerSize;//ChangedLine
bool secret = false;

//I changed the objects-inl.h
ACCESSORS_SPECIAL(JSValue ...) //instead of accessors 

//Changed the builtins-x64.cc to correct the STATIC_ASSERT(JSValue::kSize == 4* kPointerSize) to STATIC_ASSERT(JSValue::kSize == 5* kPointerSize)

Now I am getting a segmentation fault (core dumped) error at harmony. The error remains the same even if the ACCESSORS_SPECIAL is changed to ACCESSORS. 

Am I missing something ? Thanks again for your kind assistance.

Best Regards,
Deepak Subramamian

Deepak Subramanian

unread,
May 28, 2015, 10:32:49 AM5/28/15
to v8-u...@googlegroups.com
I should make it more clear. The error comes just after the step LINK mksnapshot.

Second, I am not sure if this is something to do with harmony but since I was printing a lot of stuff, the last slow property to be added was harmony_unicode.

The error itself just happens. 

When I rerun compilation of d8, I get.. (at the final linking step)

FAILED: ../../third_party/llvm-build/Release+Asserts/bin/clang++ -pthread -m64 -o d8 -Wl,--start-group obj/src/d8.d8.o obj/src/d8.d8-posix.o obj/src/d8.d8-debug.o obj/src/gen/d8.d8-js.o obj/tools/gyp/libv8_libplatform.a obj/third_party/icu/libicui18n.a obj/third_party/icu/libicuuc.a obj/tools/gyp/libv8_base.a obj/tools/gyp/libv8_libbase.a obj/third_party/icu/libicudata.a obj/tools/gyp/libv8_snapshot.a -Wl,--end-group  -lrt
obj/tools/gyp/../../src/v8_base.snapshot-common.o: In function `v8::internal::Snapshot::HaveASnapshotToStartFrom()':
/HIDDENPATH/v8/out/Debug/../../src/snapshot-common.cc:18: undefined reference to `v8::internal::Snapshot::SnapshotBlob()'
obj/tools/gyp/../../src/v8_base.snapshot-common.o: In function `v8::internal::Snapshot::EmbedsScript()':
/HIDDENPATH/v8/out/Debug/../../src/snapshot-common.cc:32: undefined reference to `v8::internal::Snapshot::SnapshotBlob()'
obj/tools/gyp/../../src/v8_base.snapshot-common.o: In function `v8::internal::Snapshot::Initialize(v8::internal::Isolate*)':
/HIDDENPATH/v8/out/Debug/../../src/snapshot-common.cc:42: undefined reference to `v8::internal::Snapshot::SnapshotBlob()'
obj/tools/gyp/../../src/v8_base.snapshot-common.o: In function `v8::internal::Snapshot::NewContextFromSnapshot(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSGlobalProxy>, v8::internal::Handle<v8::internal::FixedArray>*)':
/HIDDENPATH/v8/out/Debug/../../src/snapshot-common.cc:63: undefined reference to `v8::internal::Snapshot::SnapshotBlob()'
clang-3.6: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Sven Panne

unread,
May 29, 2015, 2:19:57 AM5/29/15
to v8-u...@googlegroups.com
On Thu, May 28, 2015 at 3:52 PM, Deepak Subramanian <subud...@gmail.com> wrote:
[...]
ACCESSORS_SPECIAL(JSValue ...) //instead of accessors 

What is ACCESSORS_SPECIAL? 

//Changed the builtins-x64.cc to correct the STATIC_ASSERT(JSValue::kSize == 4* kPointerSize) to STATIC_ASSERT(JSValue::kSize == 5* kPointerSize)

There's a reason that we have an assert there, read the comment above it, just silencing it it not enough. :-) You have to fully initialize the new field of your JSValue (there might be more places than builtins.x64.cc, don't know), and depending on what's in there (boxed/unboxed value), you might have to change the GC, too (see heap/objects_visiting.cc).
 
Now I am getting a segmentation fault (core dumped) error at harmony. The error remains the same even if the ACCESSORS_SPECIAL is changed to ACCESSORS. 

Very probably your problems has nothing to do with Harmony at all, and you linking problem might just be a bug in our build system (IIRC I've seen something similar before). Just do a "make clean" and rebuild...

In general I would highly recommend debug builds and perhaps some help from valgrind to debug problems like this.

Deepak Subramanian

unread,
Jun 3, 2015, 4:57:45 AM6/3/15
to v8-u...@googlegroups.com
Hi,

I think I solved it for the most part thanks to you. However I am still stuck on a few things :)

1. I did solve it using the built-ins.x64.cc - so I had to initialize the memory space. I did do that now. I just added a new line with the memory offset of the new variable in the blocked address space. That has made all bugs dissapear. I saw the GC as well. Now that it a boxed value, I have no reason to print it, right ?.
2. ACCESSORS_SPECIAL is currently the same as ACCESSORS with some print statements. Sadly none of my print statements are getting printed. I do not get any errors either and everything is working as normal ! So I am not sure what is wrong. Do my actions have any effect ? Why is any printf added here not getting printed ? Thanks.

Thanks a lot for your continuous support.

Best Regards,
Deepak Subramanian

Sven Panne

unread,
Jun 3, 2015, 5:35:46 AM6/3/15
to v8-u...@googlegroups.com
On Wed, Jun 3, 2015 at 10:57 AM, Deepak Subramanian <subud...@gmail.com> wrote:
1. [...] Now that it a boxed value, I have no reason to print it, right ?.

I don't understand that question, could you elaborate?
 
2. ACCESSORS_SPECIAL is currently the same as ACCESSORS with some print statements. Sadly none of my print statements are getting printed. I do not get any errors either and everything is working as normal ! So I am not sure what is wrong. Do my actions have any effect ? Why is any printf added here not getting printed ?[...]

The ACCESSORS macro magic is only for getting/setting object fields from the C++ side, which happens rarely for most fields. If the fields are accessed via generated or handwritten machine code, those macros don't matter. To get the full picture, grep for e.g. JSValue::kValueOffset.

Deepak Subramanian

unread,
Jun 3, 2015, 5:44:22 AM6/3/15
to v8-u...@googlegroups.com

Thanks for the rapid response Sven.
The first question is actually mistyped :) 
1. I meant now that it a boxed value, I have no reason to add more statements in the GC, right ?. [Atleast from my understanding of the GC]
2. Cool. Let me make my query simple then. Everytime, the JSValue's value is accessed on the c++ part, I want to print "value was accessed". Everytime the set_value() is accessed, I want to print "value was set". Is this possible ?

Thanks again. [Could it be possible to take this on an IRC chat or something so I don't spam this forum ?]

Best Regards,
Deepak Subramanian

Sven Panne

unread,
Jun 3, 2015, 7:00:38 AM6/3/15
to v8-u...@googlegroups.com
On Wed, Jun 3, 2015 at 11:44 AM, Deepak Subramanian <subud...@gmail.com> wrote:
1. I meant now that it a boxed value, I have no reason to add more statements in the GC, right ?. [Atleast from my understanding of the GC]

Yes, the GC should need no changes if the new field is boxed.
 
2. Cool. Let me make my query simple then. Everytime, the JSValue's value is accessed on the c++ part, I want to print "value was accessed". Everytime the set_value() is accessed, I want to print "value was set". Is this possible ?

That's what the ACCESSOR macros are for. But as I mentioned earlier, this will probably not help you in general:

   * They are only for accesses from C++ land, for the whole story you would have to modify the Fullcode/Crankshaft/TurboFan compilers, too.

   * I'm not totally sure what you're trying to achieve: JSValues are just (relatively rare) wrapper objects, not JavaScript values in general. It might be the case that you actually want to handle JSReceiver/JSObject entities specially, but that's *far* more complicated and would be a huge undertaking. It would help if you could explain what you're trying to achieve.
 
Thanks again. [Could it be possible to take this on an IRC chat or something so I don't spam this forum ?]

I don't consider this spam, that's exactly the kind of questions v8-users@ is for IMHO.

Deepak Subramanian

unread,
Jun 3, 2015, 7:49:01 AM6/3/15
to v8-u...@googlegroups.com
Let me explain in greater detail on the goal then..

I want to have 2 values for every object and be able to determine which of the two values to use at runtime. 

JSValue might not be what I want then (if it so rarely used). Lets say there is a variable var a. I want it to have it to have a->value = "something" and a->secretValue = "something else". 

I will write a policy to say a function f1 can access a.secret. So if it is this function call in the stack, I would change the value of a provided to the function to a->secretValue. for the rest of the functions, I would use a->value.

I thought that JSValue is the wrapper for all strings, ints and booleans. Hence, I looked into it here. I thought overloading the value() and set_value() functions would be sufficient to achieve my goal. :)

So my short term goal is to find how to know whenever a value of a "string" is being set or accessed or changed. 

Thanks.

Best Regards,
Deepak 

Deepak Subramanian

unread,
Jun 3, 2015, 8:04:24 AM6/3/15
to v8-u...@googlegroups.com
I had tried to do thid from the RuntimeReference_SetValueOf at runtime-objects but since it appears to be a reference implementation, I tried to follow .. 

Even modifying these runtimes should suffice for my context but the runtime functions seem to be executed only initially. I have disabled crankshaft to the best of my knowledge (since efficiency is not as important)

Deepak Subramanian

unread,
Jun 4, 2015, 8:27:31 AM6/4/15
to v8-u...@googlegroups.com
I would also like to know how to force run all JS tests.  (Just to check I have not broken something)

Deepak Subramanian

unread,
Jun 12, 2015, 8:29:24 AM6/12/15
to v8-u...@googlegroups.com
Hi. I guess I explained too much :)

Let me make the query simple.

I want to add a boolean value in class Object. bool secret = true;

To do this, what are the other related things I must change ? It seems that doing this crashes the application when I change the value.

Thanks.

Reply all
Reply to author
Forward
0 new messages