There is something that I can't quite really understand about stack-based virtual machines: What is the type of the value that is stored in the stack? What I mean is that for example, if I pushed an integer onto the stack, it's clear that it's type is a 32-bit integer. However, if I push a float, a string or even an object reference (in OOPs), their types change. When the stack is created, does it figure out their type as they are pushed on the stack, or does the stack have a predefined entry type, such as only integers, or maybe a pointer? I can't really figure it out, so any help is appreciated.
Type of a stack entry (in a virtual machine)
305 Views Asked by Kai At
1
There are 1 best solutions below
Related Questions in TYPES
- Need clarification on VHDL expressions involving std_logic_vector, unsigned and literals, unsure about compiler interpretation
- Adding a different string to a table fails
- The type of B is displayed as A when `type B = A` is used. Why is it displayed as `any` when `type B = A | A` is used instead?
- why we got same data type in two versions like "int" and "integer" in php?
- Handling NaN entries in a dataframe created from CSV
- Cannot find type definition file for 'node' in react project
- Correct way to count types in whole corpus
- Typescript: how to get possible keys from const with limited values?
- Having two Image types in React TypeScript one for upload, one for display
- MOOC.fi Java Programming course 1 - Exercise 13 "Exercises" Part 6 - Compilation error
- Is is a mistake to use type keyword after curly braces in TS when importing constants and files fro one file?
- type annotations needed, try using a fully qualified path to specify the expected types
- Need a simple example how to catch a data type error en C++
- Pyspark reads data as string but on Mongo they are double
- Extract a Maybe from a heterogeneous collection
Related Questions in STACK
- What is causing my towers of hanoi logic to infinitely loop?
- Asking code suggestions about data structure and algorithm
- Why is 'EDITBIN /STACK:2097152 w3wp.exe' cmd is giving me an LNK1342 error?
- issues with circular queues
- Missing PAGE_GUARD flag on the memory of stack for one windows application
- Purpose of stack register(s) in holding 0x7c00
- Split Dataframe and stack horizontally
- segmentation fault (core dumped) in C programming
- How to find Find max right using stack?
- Does an Stackoverflow occur in the JVM if the Activation Record is too small but there is still space left in the general stack?
- How to create 100 maps with bootstrapping using stacked ensemble fit with tidymodels
- How does the class Exchanger in Java actually work?
- How can I improve the iterative approach to be faster than recursive implementation, as usual?
- Need to make Stack cards on nav click as well ass page scroll with help of jquery
- Puncover: Stack column is empty after analysis
Related Questions in VM-IMPLEMENTATION
- MRI: Why are some methods implemented as aliases, but others duplicated?
- expected dimension but got
- Encoding a .json file for a bytecode vm
- Does Dalvik create stacks to manage threads
- How would I be able to make a register-based virtual machine code off of a Binary Tree for math interpretation
- How do virtual machines like Lua or JVM represent (and work on) larger data types?
- Why does LuaJIT bytecode put the opcode at the end instead of the front?
- Load anticipation of Application serve instances in a VM
- Why does Concurrent-Mark-Sweep (CMS) remark phase need to re-examine the thread-stacks instead of just looking at the mutator's write-queues?
- What happens exactly under the hood to Assembly `push`, `pop`, `call`, and `ret` operations?
- How to simulate a call stack in JavaScript using only a single array
- C Virtual machine Command with same opcode
- Decoding instruction of hypothetical CPU
- Optimization techniques for backtracking regex implementations
- How to fix: OP-code isn't read out correctly
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
There are various approaches, I just give few examples here.
In V8 JavaScript engine VM (form Chrome browser and Node.js) all objects on a stack a pointers to a structure wich might be similar to this:
JavaScript VM of Firefox's SpiderMonkey holds 64 bit values on stack, those values are so called NaN-boxed. If higher 3 bits are all set to
1the next few bits are used to determine the object type, and the rest 48 bits are used as a pointer to the object structure. If the 3 most significant bits are not all111then the whole 64 bit value is adouble.The VM stack in a garbage collected environment usually must hold homogenous objects, i.e. objects of the same type, not mixing pointers and integers for instance, so that garbage collector can successfully walk through and check every object recursively starting from stack. For example a value on stack that looks like
0x123456789can be both a valid integer and a valid pointer, and a garbage collector has no idea to ignore it (if it was an integer) or dereference it (to a potentially wrong memory location).In fact there are advanced garbage collectors that can actually work with mixed data in the stack making some assumptions, guessing, and keeping extra book keeping.