Alien-LibJIT

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN


                     END OF TERMS AND CONDITIONS

        Appendix: How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.

  To do so, attach the following notices to the program.  It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 1, or (at your option)
    any later version.

libjit/COPYING  view on Meta::CPAN

POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

libjit/COPYING.LESSER  view on Meta::CPAN

		     END OF TERMS AND CONDITIONS

           How to Apply These Terms to Your New Libraries

  If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

  To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    <one line to give the library's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

libjit/ChangeLog  view on Meta::CPAN

	sub-function throws an exception, not 1.

2004-10-31  Rhys Weatherley  <rweather@southern-storm.com.au>

	* jit/jit-rules-x86.sel: handle the special case of constant
	destination pointers in "store_relative" instructions, because
	otherwise the register allocator gets confused.

2004-10-29  Peter Lund <firefly@diku.dk>

	* doc/libjit.3: fix manpage formatting issues. (patch attached
	to bug #10779, Gopal).

2004-10-28  Rhys Weatherley  <rweather@southern-storm.com.au>

	* configure.in, jit/jit-debugger.c, jit/jit-thread.c,
	jit/jit-thread.h: implement some of the locking code
	for the debugging API.

2004-10-12  Evin Robertson  <evin@users.sourceforge.net>

libjit/doc/libjit.texi  view on Meta::CPAN

    virtual void build();

protected:
    virtual jit_type_t create_signature();
@};
@end example

Where we used @code{jit_function_t} and @code{jit_context_t} before,
we now use the C++ @code{jit_function} and @code{jit_context} classes.

In our constructor, we attach ourselves to the context and then call
the @code{create()} method.  This is in turn will call our overridden
virtual method @code{create_signature()} to obtain the signature:

@example
jit_type_t mul_add_function::create_signature()
@{
    // Return type, followed by three parameters,
    // terminated with "end_params".
    return signature_helper
        (jit_type_int, jit_type_int, jit_type_int,

libjit/include/jit/jit-debugger.h  view on Meta::CPAN


jit_debugger_thread_id_t jit_debugger_get_self(jit_debugger_t dbg) JIT_NOTHROW;
jit_debugger_thread_id_t jit_debugger_get_thread
		(jit_debugger_t dbg, const void *native_thread) JIT_NOTHROW;
int jit_debugger_get_native_thread
		(jit_debugger_t dbg, jit_debugger_thread_id_t thread,
		 void *native_thread) JIT_NOTHROW;
void jit_debugger_set_breakable
		(jit_debugger_t dbg, const void *native_thread, int flag) JIT_NOTHROW;

void jit_debugger_attach_self
		(jit_debugger_t dbg, int stop_immediately) JIT_NOTHROW;
void jit_debugger_detach_self(jit_debugger_t dbg) JIT_NOTHROW;

int jit_debugger_wait_event
		(jit_debugger_t dbg, jit_debugger_event_t *event,
		 jit_int timeout) JIT_NOTHROW;

jit_debugger_breakpoint_id_t jit_debugger_add_breakpoint
		(jit_debugger_t dbg, jit_debugger_breakpoint_info_t info) JIT_NOTHROW;
void jit_debugger_remove_breakpoint

libjit/jit/jit-block.c  view on Meta::CPAN

				block->preds[index] = block->preds[index + 1];
			}
			block->preds = jit_realloc(block->preds,
						   block->num_preds * sizeof(_jit_edge_t));
			return;
		}
	}
}

static void
attach_edge_dst(_jit_edge_t edge, jit_block_t block)
{
	_jit_edge_t *preds;

	preds = jit_realloc(block->preds, (block->num_preds + 1) * sizeof(_jit_edge_t));
	if(!preds)
	{
		jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
	}

	preds[block->num_preds++] = edge;

libjit/jit/jit-block.c  view on Meta::CPAN

	for(index = 0; index < block->num_preds; index++)
	{
		pred_edge = block->preds[index];
		if(pred_edge->flags == _JIT_EDGE_FALLTHRU)
		{
			fallthru_edge = pred_edge;
		}
		else
		{
			*changed = 1;
			attach_edge_dst(pred_edge, succ_block);
		}
	}

	/* Unless the block is taken address of, the incoming fallthrough edge
	   can be retargeted and then the block deleted if the outgoing edge is
	   also fallthrough. */
	if(!block->address_of && fallthru_edge && succ_edge->flags == _JIT_EDGE_FALLTHRU)
	{
		*changed = 1;
		attach_edge_dst(fallthru_edge, succ_block);
		fallthru_edge = 0;
	}

	/* Free the block if there is no incoming edge left and it is not taken
	   address of. Otherwise adjust the preds array accordingly.  */
	if(fallthru_edge)
	{
		if(block->num_preds > 1)
		{
			block->num_preds = 1;

libjit/jit/jit-block.c  view on Meta::CPAN

}

void
_jit_block_detach(jit_block_t first, jit_block_t last)
{
	last->next->prev = first->prev;
	first->prev->next = last->next;
}

void
_jit_block_attach_after(jit_block_t block, jit_block_t first, jit_block_t last)
{
	first->prev = block;
	last->next = block->next;
	block->next->prev = last;
	block->next = first;
}

void
_jit_block_attach_before(jit_block_t block, jit_block_t first, jit_block_t last)
{
	first->prev = block->prev;
	last->next = block;
	block->prev->next = first;
	block->prev = last;
}

/* Make space for the label in the label info table */
static int
ensure_label_table(jit_function_t func, jit_label_t label)

libjit/jit/jit-debugger.c  view on Meta::CPAN

A thread stopped at a breakpoint that wasn't explicitly defined by
a call to @code{jit_debugger_add_breakpoint}.  This typicaly results
from a call to a "step" function like @code{jit_debugger_step}, where
execution stopped at the next line but there isn't an explicit breakpoint
on that line.

@item JIT_DEBUGGER_TYPE_USER_BREAKPOINT
A thread stopped because of a call to @code{jit_debugger_break}.

@item JIT_DEBUGGER_TYPE_ATTACH_THREAD
A thread called @code{jit_debugger_attach_self}.  The @code{data1} field
of the event is set to the value of @code{stop_immediately} for the call.

@item JIT_DEBUGGER_TYPE_DETACH_THREAD
A thread called @code{jit_debugger_detach_self}.
@end table

@deftypefun int jit_insn_mark_breakpoint_variable (jit_function_t @var{func}, jit_value_t @var{data1}, jit_value_t @var{data2})
This function is similar to @code{jit_insn_mark_breakpoint} except that values
in @var{data1} and @var{data2} can be computed at runtime. You can use this
function for example to get address of local variable.

libjit/jit/jit-debugger.c  view on Meta::CPAN

 * and compatible with the debugger's requirements.
 * @end deftypefun
@*/
int jit_debugging_possible(void)
{
	return JIT_THREADS_SUPPORTED;
}

/*@
 * @deftypefun jit_debugger_t jit_debugger_create (jit_context_t @var{context})
 * Create a new debugger instance and attach it to a JIT @var{context}.
 * If the context already has a debugger associated with it, then this
 * function will return the previous debugger.
 * @end deftypefun
@*/
jit_debugger_t jit_debugger_create(jit_context_t context)
{
	jit_debugger_t dbg;
	if(context)
	{
		if(context->debugger)

libjit/jit/jit-debugger.c  view on Meta::CPAN

	lock_debugger(dbg);
	th = get_specific_thread(dbg, id);
	if(th)
	{
		th->breakable = flag;
	}
	unlock_debugger(dbg);
}

/*@
 * @deftypefun void jit_debugger_attach_self (jit_debugger_t @var{dbg}, int @var{stop_immediately})
 * Attach the current thread to a debugger.  If @var{stop_immediately}
 * is non-zero, then the current thread immediately suspends, waiting for
 * the user to start it with @code{jit_debugger_run}.  This function is
 * typically called in a thread's startup code just before any "real work"
 * is performed.
 * @end deftypefun
@*/
void jit_debugger_attach_self(jit_debugger_t dbg, int stop_immediately)
{
	jit_debugger_event_t *event;
	jit_debugger_thread_t th;
	lock_debugger(dbg);
	th = get_current_thread(dbg);
	if(th)
	{
		event = alloc_event();
		if(event)
		{

libjit/jit/jit-debugger.c  view on Meta::CPAN

		(*(context->debug_hook))(func, data1, data2);
	}

	/* Ignore breakpoints with data1 values less than 10000.  These are
	   presumed to be handled by a user-supplied debug hook instead */
	if(data1 < JIT_DEBUGGER_DATA1_FIRST)
	{
		return;
	}

	/* Determine if there is a debugger attached to the context */
	dbg = context->debugger;
	if(!dbg)
	{
		return;
	}

	/* Lock down the debugger while we do this */
	lock_debugger(dbg);

	/* Get the current thread's information block */

libjit/jit/jit-dump.c  view on Meta::CPAN

	unlink(o_path);
	putc('\n', stream);
	fflush(stream);
}

#endif /* !JIT_BACKEND_INTERP */

/*@
 * @deftypefun void jit_dump_function (FILE *@var{stream}, jit_function_t @var{func}, const char *@var{name})
 * Dump the three-address instructions within a function to a stream.
 * The @var{name} is attached to the output as a friendly label, but
 * has no other significance.
 *
 * If the function has not been compiled yet, then this will dump the
 * three address instructions from the build process.  Otherwise it will
 * disassemble and dump the compiled native code.
 * @end deftypefun
@*/
void jit_dump_function(FILE *stream, jit_function_t func, const char *name)
{
	jit_block_t block;

libjit/jit/jit-insn.c  view on Meta::CPAN

	if(!_jit_block_record_label(block, *label))
	{
		_jit_block_destroy(block);
		return 0;
	}

	/* If the block is newly created then insert it to the end of
	   the function's block list */
	if(block != func->builder->current_block)
	{
		_jit_block_attach_before(func->builder->exit_block, block, block);
		func->builder->current_block = block;
	}

	return 1;
}

/*@
 * @deftypefun int jit_insn_new_block (jit_function_t @var{func})
 * Start a new basic block, without giving it an explicit label.
 * @end deftypefun

libjit/jit/jit-insn.c  view on Meta::CPAN

#ifdef _JIT_BLOCK_DEBUG
	label = (func->builder->next_label)++;
	if(!_jit_block_record_label(block, label))
	{
		_jit_block_destroy(block);
		return 0;
	}
#endif

	/* Insert the block to the end of the function's block list */
	_jit_block_attach_before(func->builder->exit_block, block, block);
	func->builder->current_block = block;

	return 1;
}

int _jit_load_opcode(int base_opcode, jit_type_t type,
					 jit_value_t value, int no_temps)
{
	type = jit_type_normalize(type);
	if(!type)

libjit/jit/jit-insn.c  view on Meta::CPAN

		if (!block) {
			return 0;
		}
	}

	/* The last block is excluded from the blocks to move */
	block = last->prev;

	/* Move the blocks to the end */
	_jit_block_detach(first, block);
	_jit_block_attach_before(func->builder->exit_block, first, block);
	func->builder->current_block = block;

	/* Create a new block after the last one we moved, to start fresh */
	return jit_insn_new_block(func);
}

/*@
 * @deftypefun int jit_insn_move_blocks_to_start (jit_function_t @var{func}, jit_label_t @var{from_label}, jit_label_t @var{to_label})
 * Move all of the blocks between @var{from_label} (inclusive) and
 * @var{to_label} (exclusive) to the start of the current function.

libjit/jit/jit-insn.c  view on Meta::CPAN

	/* The last block is excluded from the blocks to move */
	block = last->prev;

	/* Update the init block pointer */
	func->builder->init_block = block;

	/* Move the blocks after the original init block */
	if(init->next != first)
	{
		_jit_block_detach(first, block);
		_jit_block_attach_after(init, first, block);
	}

	/* Done */
	return 1;
}

/*@
 * @deftypefun int jit_insn_mark_offset (jit_function_t @var{func}, jit_int @var{offset})
 * Mark the current position in @var{func} as corresponding to the
 * specified bytecode @var{offset}.  This value will be returned

libjit/jit/jit-internal.h  view on Meta::CPAN

void _jit_block_destroy(jit_block_t block);

/*
 * Detach blocks from their current position in a function.
 */
void _jit_block_detach(jit_block_t first, jit_block_t last);

/*
 * Attach blocks to a function after a specific position.
 */
void _jit_block_attach_after(jit_block_t block, jit_block_t first, jit_block_t last);

/*
 * Attach blocks to a function before a specific position.
 */
void _jit_block_attach_before(jit_block_t block, jit_block_t first, jit_block_t last);

/*
 * Record the label mapping for a block.
 */
int _jit_block_record_label(jit_block_t block, jit_label_t label);

/*
 * Record the label flags.
 */
int _jit_block_record_label_flags(jit_function_t func, jit_label_t label, int flags);

libjit/jit/jit-memory-cache.c  view on Meta::CPAN

regular code between "try" blocks.

The jit_cache_method blocks are organised into a red-black tree, which
is used to perform fast lookups by address (_jit_cache_get_method).  These
lookups are used when walking the stack during exceptions or security
processing.

Each method can also have offset information associated with it, to map
between native code addresses and offsets within the original bytecode.
This is typically used to support debugging.  Offset information is stored
as auxiliary data, attached to the jit_cache_method block.

Threading issues
----------------

Writing a method to the cache, querying a method by address, or querying
offset information for a method, are not thread-safe.  The caller should
arrange for a cache lock to be acquired prior to performing these
operations.

Executing methods from the cache is thread-safe, as the method code is

libjit/jit/jit-meta.c  view on Meta::CPAN

graphs, branch prediction information, or any other information that is
useful to optimizers or code generators.

Metadata can also be used by higher level user code to store information
about the structures that is specific to the user's virtual machine or
language.

The library structures have special-purpose metadata routines associated
with them (e.g. @code{jit_function_set_meta}, @code{jit_block_get_meta}).
However, sometimes you may wish to create your own metadata lists and
attach them to your own structures.  The functions below enable you
to do this:

@*/

/*@
 * @deftypefun int jit_meta_set (jit_meta_t *@var{list}, int @var{type}, void *@var{data}, jit_meta_free_func @var{free_data}, jit_function_t @var{pool_owner})
 * Set a metadata value on a list.  If the @var{type} is already present
 * in the list, then its previous value will be freed.  The @var{free_func}
 * is called when the metadata value is freed with @code{jit_meta_free}
 * or @code{jit_meta_destroy}.  Returns zero if out of memory.

libjit/jit/jit-rules.h  view on Meta::CPAN

	   but there are no actual "jit_value_t" objects associated */
	char			used_for_temp;
};

/*
 * Code generation information.
 */
typedef struct jit_gencode *jit_gencode_t;
struct jit_gencode
{
	jit_context_t		context;	/* Context this position is attached to */
	unsigned char		*ptr;		/* Current code pointer */
	unsigned char		*mem_start;	/* Available space start */
	unsigned char		*mem_limit;	/* Available space limit */
	unsigned char		*code_start;	/* Real code start */
	unsigned char		*code_end;	/* Real code end */
	jit_regused_t		permanent;	/* Permanently allocated global regs */
	jit_regused_t		touched;	/* All registers that were touched */
	jit_regused_t		inhibit;	/* Temporarily inhibited registers */
	jit_regcontents_t	contents[JIT_NUM_REGS]; /* Contents of each register */
	int			current_age;	/* Current age value for registers */

libjit/jit/jit-type.c  view on Meta::CPAN

 *
 * Normalization is typically used prior to applying a binary numeric
 * instruction, to make it easier to determine the common type.
 * It will also remove tags from the specified type.
 * @end deftypefun
@*/
jit_type_t jit_type_normalize(jit_type_t type)
{
	while(type && type->kind >= JIT_TYPE_FIRST_TAGGED)
	{
		/* Remove any tags that are attached to the type */
		type = type->sub_type;
	}
	if(!type)
	{
		return type;
	}
	if(type == jit_type_nint || type->kind == JIT_TYPE_PTR ||
	   type->kind == JIT_TYPE_SIGNATURE)
	{
	#ifdef JIT_NATIVE_INT32

libjit/jitruby/ext/method_data.c.rpp  view on Meta::CPAN

  FIX_FRAME();
  result = (*actual_cfunc())(self, #{args});
  return result;
}
    END
  end

  nil
END

/* Define a method and attach data to it.
 *
 * The method looks to ruby like a normal aliased CFUNC, with a modified
 * origin class:
 *
 * NODE_FBODY
 *   |- (u1) orig - origin class
 *   |  |- basic
 *   |  |  |- flags - origin class flags + FL_SINGLETON
 *   |  |  +- klass - NODE_MEMO
 *   |  |     |- (u1) cfnc - actual C function to call

libjit/jitruby/ext/method_data.c.rpp  view on Meta::CPAN

    case #{i}: data_wrapper = RUBY_METHOD_FUNC(data_wrapper_#{i}); break;
    END
  end
  nil
END
    case -1: data_wrapper = RUBY_METHOD_FUNC(data_wrapper_m1); break;
    default: rb_raise(rb_eArgError, "unsupported arity %d", arity);
  }

  FL_SET(origin, FL_SINGLETON);
  rb_singleton_class_attached(origin, klass);
  rb_name_class(origin, SYM2ID(rb_class_name(klass)));

  RBASIC(origin)->klass = (VALUE)NEW_NODE(NODE_MEMO, cfunc, data, 0);

#ifdef RUBY_VM
  /* YARV */
  node = NEW_FBODY(
      NEW_METHOD(
          NEW_CFUNC(data_wrapper, arity),
          origin,



( run in 0.972 second using v1.01-cache-2.11-cpan-e1769b4cff6 )