github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-init.c (about)

     1  /*
     2   * jit-init.c - Initialization routines for the JIT.
     3   *
     4   * Copyright (C) 2004  Southern Storm Software, Pty Ltd.
     5   *
     6   * This file is part of the libjit library.
     7   *
     8   * The libjit library is free software: you can redistribute it and/or
     9   * modify it under the terms of the GNU Lesser General Public License
    10   * as published by the Free Software Foundation, either version 2.1 of
    11   * the License, or (at your option) any later version.
    12   *
    13   * The libjit library is distributed in the hope that it will be useful,
    14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16   * Lesser General Public License for more details.
    17   *
    18   * You should have received a copy of the GNU Lesser General Public
    19   * License along with the libjit library.  If not, see
    20   * <http://www.gnu.org/licenses/>.
    21   */
    22  
    23  #include "jit-internal.h"
    24  #include "jit-rules.h"
    25  
    26  /*@
    27   * @deftypefun void jit_init (void)
    28   * This is normally the first function that you call when using
    29   * @code{libjit}.  It initializes the library and prepares for
    30   * JIT operations.
    31   *
    32   * The @code{jit_context_create} function also calls this, so you can
    33   * avoid using @code{jit_init} if @code{jit_context_create} is the first
    34   * JIT function that you use.
    35   *
    36   * It is safe to initialize the JIT multiple times.  Subsequent
    37   * initializations are quietly ignored.
    38   * @end deftypefun
    39  @*/
    40  void
    41  jit_init(void)
    42  {
    43  	static int init_done = 0;
    44  
    45  	/* Make sure that the thread subsystem is initialized */
    46  	_jit_thread_init();
    47  
    48  	/* Make sure that the initialization is done only once
    49  	   (requires the global lock initialized above) */
    50  	jit_mutex_lock(&_jit_global_lock);
    51  	if(init_done)
    52  	{
    53  		goto done;
    54  	}
    55  	init_done = 1;
    56  
    57  #ifdef JIT_USE_SIGNALS
    58  	/* Initialize the signal handlers */
    59  	_jit_signal_init();
    60  #endif
    61  
    62  	/* Initialize the virtual memory system */
    63  	jit_vmem_init();
    64  
    65  	/* Initialize the backend */
    66  	_jit_init_backend();
    67  
    68  done:
    69  	jit_mutex_unlock(&_jit_global_lock);
    70  }
    71  
    72  /*@
    73   * @deftypefun int jit_uses_interpreter (void)
    74   * Determine if the JIT uses a fall-back interpreter to execute code
    75   * rather than generating and executing native code.  This can be
    76   * called prior to @code{jit_init}.
    77   * @end deftypefun
    78  @*/
    79  int
    80  jit_uses_interpreter(void)
    81  {
    82  #if defined(JIT_BACKEND_INTERP)
    83  	return 1;
    84  #else
    85  	return 0;
    86  #endif
    87  }
    88  
    89  /*@
    90   * @deftypefun int jit_supports_threads (void)
    91   * Determine if the JIT supports threads.
    92   * @end deftypefun
    93  @*/
    94  int
    95  jit_supports_threads(void)
    96  {
    97  	return JIT_THREADS_SUPPORTED;
    98  }
    99  
   100  /*@
   101   * @deftypefun int jit_supports_virtual_memory (void)
   102   * Determine if the JIT supports virtual memory.
   103   * @end deftypefun
   104  @*/
   105  int
   106  jit_supports_virtual_memory(void)
   107  {
   108  	return JIT_VMEM_SUPPORTED;
   109  }