Giter Club home page Giter Club logo

llvm-statepoint-utils's Introduction

LLVM Statepoint Utilities

Build Status

LLVM's statepoint infrastructure generates stack frame layout information to enable precise garbage collection. However, the information is not in a suitable form for efficient lookups by an actual garbage collector scanning the stack. This design is intentional because "the runtime is expected to parse the [stack map] immediately after compiling a module and encode the information in its own format."

The utilities herein are designed to do just that: it can generate an efficient hash table at runtime that can be used by a garbage collector to walk the stack and find all pointers. Generating the table at runtime works around issues with position independent code, since the table is keyed on absolute return addresses. The code is pure, unadulterated C99* with no dependencies and a permissive license.

Note that this library was designed to work for programs whose stack map information was generated solely by gc.statepoint intrinsics, as these intrinsics generate specially formatted stack map records. If you're mixing patchpoint or regular stackmap intrinsics in the same code, you might need to modify the library in addition to marking call sites to differentiate them from statepoints.

The currently supported Stackmap Format is version 3, which is found in LLVM 5+.

how to build and use

  1. Run OPT_FLAG="-O3 -DNDEBUG" make
  2. Look inside dist and you should see a library file and a header file
  3. Enjoy

* almost... we rely on the packed attribute supported by popular C compilers (i.e., clang and gcc).

including these utils in your project

You can generate a single .c and corresponding .h file for inclusion in your own build system. To do this, run make unified, and the output code will be placed under build/.

a fancier implementation

To avoid having to generate the hash table each time the program starts up, you could extend this utility to instead generate a position-independent, static, callsite-offset table. For example, to lookup information about a callsite, we would:

  1. Take the return address, and subtract from it the starting address of the .text section, to obtain the callsite offset. The starting address would change on each launch because of ASLR, but it can be determined once during program startup and saved to a global variable.

  2. Use the call-site offset as the key into the statically allocated table. There are various ways of doing this, such as using a perfect hash function + a pointer array, or generating a standard hash table that is laid out statically in the data section.

llvm-statepoint-utils's People

Contributors

kavon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

llvm-statepoint-utils's Issues

Non-indirect locations end up as bogus stack frame offsets.

Sometimes, LLVM will re-materialize GC root that it has proven to be a constant (that is obviously not a pointer) instead of saving it to the stack frame. Thus, the "relocation" entry in the emitted stackmap data is a Constant and not an Indirect, which is a frame location:

LBB42_43:                               ## %else_cfgE935_1391E
	movq	%r8, 8(%rsp)
	movq	%r14, 16(%rsp)
	movl	$1, %edi                   # <<< this is a root
	movl	$1, %eax
	movl	$1, %r10d
	movq	%r8, %r12
	callq	_lp_cfgE30B_FD42
Ltmp153:
	movl	$1, %edi                      # <<< this is a root rematerialized.
	movq	8(%rsp), %r10
	movq	16(%rsp), %rcx
	jmp	LBB42_11

Of course, our hash table generator does not expect such things, and just puts a bogus offset in the table instead of crashing the program or warning.

	** frame #1**
		return address: 0x1000091ED
		frame size: 56
		num live ptrs: 3
		ptr slot #0 { kind: base ptr, frame offset: 123456789 }
		ptr slot #1 { kind: base ptr, frame offset: 16 }
		ptr slot #2 { kind: base ptr, frame offset: 8 }

example program

im trying to make a gc using this tool, but can't seem to get wailking the stack right. An example program would be great for this. I already looked at the test folder but it did not help me enough.

If this is out of scope of this project please ignore.

C++ support

The header needs a compound linkage specification (extern "C" {..}) wrapped around it.

Asking the difference between the statepoint and safepoint

Hi @kavon,

First of all, I need to thank you for this great job.

I have started on working GC related things and currently I am trying to understand the LLVM GC framework support. When I read the LLVM docs pointed in readme, I found two terms statepoint and safepoint. Could you please explain me the difference between these two?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.