PostgreSQL Source Code git master
jit.c File Reference
#include "postgres.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "fmgr.h"
#include "jit/jit.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "portability/instr_time.h"
#include "utils/fmgrprotos.h"
Include dependency graph for jit.c:

Go to the source code of this file.

Functions

static bool provider_init (void)
 
Datum pg_jit_available (PG_FUNCTION_ARGS)
 
void jit_reset_after_error (void)
 
void jit_release_context (JitContext *context)
 
bool jit_compile_expr (struct ExprState *state)
 
void InstrJitAgg (JitInstrumentation *dst, JitInstrumentation *add)
 

Variables

bool jit_enabled = true
 
char * jit_provider = NULL
 
bool jit_debugging_support = false
 
bool jit_dump_bitcode = false
 
bool jit_expressions = true
 
bool jit_profiling_support = false
 
bool jit_tuple_deforming = true
 
double jit_above_cost = 100000
 
double jit_inline_above_cost = 500000
 
double jit_optimize_above_cost = 500000
 
static JitProviderCallbacks provider
 
static bool provider_successfully_loaded = false
 
static bool provider_failed_loading = false
 

Function Documentation

◆ InstrJitAgg()

◆ jit_compile_expr()

bool jit_compile_expr ( struct ExprState state)

Definition at line 151 of file jit.c.

152{
153 /*
154 * We can easily create a one-off context for functions without an
155 * associated PlanState (and thus EState). But because there's no executor
156 * shutdown callback that could deallocate the created function, they'd
157 * live to the end of the transactions, where they'd be cleaned up by the
158 * resowner machinery. That can lead to a noticeable amount of memory
159 * usage, and worse, trigger some quadratic behaviour in gdb. Therefore,
160 * at least for now, don't create a JITed function in those circumstances.
161 */
162 if (!state->parent)
163 return false;
164
165 /* if no jitting should be performed at all */
166 if (!(state->parent->state->es_jit_flags & PGJIT_PERFORM))
167 return false;
168
169 /* or if expressions aren't JITed */
170 if (!(state->parent->state->es_jit_flags & PGJIT_EXPR))
171 return false;
172
173 /* this also takes !jit_enabled into account */
174 if (provider_init())
176
177 return false;
178}
static bool provider_init(void)
Definition: jit.c:67
static JitProviderCallbacks provider
Definition: jit.c:43
#define PGJIT_EXPR
Definition: jit.h:23
#define PGJIT_PERFORM
Definition: jit.h:20
JitProviderCompileExprCB compile_expr
Definition: jit.h:78
Definition: regguts.h:323

References JitProviderCallbacks::compile_expr, PGJIT_EXPR, PGJIT_PERFORM, provider, and provider_init().

Referenced by ExecReadyExpr().

◆ jit_release_context()

void jit_release_context ( JitContext context)

Definition at line 137 of file jit.c.

138{
140 provider.release_context(context);
141
142 pfree(context);
143}
static bool provider_successfully_loaded
Definition: jit.c:44
void pfree(void *pointer)
Definition: mcxt.c:1521
JitProviderReleaseContextCB release_context
Definition: jit.h:77

References pfree(), provider, provider_successfully_loaded, and JitProviderCallbacks::release_context.

Referenced by FreeExecutorState(), and ResOwnerReleaseJitContext().

◆ jit_reset_after_error()

void jit_reset_after_error ( void  )

Definition at line 127 of file jit.c.

128{
131}
JitProviderResetAfterErrorCB reset_after_error
Definition: jit.h:76

References provider, provider_successfully_loaded, and JitProviderCallbacks::reset_after_error.

Referenced by PostgresMain().

◆ pg_jit_available()

Datum pg_jit_available ( PG_FUNCTION_ARGS  )

Definition at line 56 of file jit.c.

57{
59}
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

References PG_RETURN_BOOL, and provider_init().

◆ provider_init()

static bool provider_init ( void  )
static

Definition at line 67 of file jit.c.

68{
69 char path[MAXPGPATH];
71
72 /* don't even try to load if not enabled */
73 if (!jit_enabled)
74 return false;
75
76 /*
77 * Don't retry loading after failing - attempting to load JIT provider
78 * isn't cheap.
79 */
81 return false;
83 return true;
84
85 /*
86 * Check whether shared library exists. We do that check before actually
87 * attempting to load the shared library (via load_external_function()),
88 * because that'd error out in case the shlib isn't available.
89 */
90 snprintf(path, MAXPGPATH, "%s/%s%s", pkglib_path, jit_provider, DLSUFFIX);
91 elog(DEBUG1, "probing availability of JIT provider at %s", path);
92 if (!pg_file_exists(path))
93 {
95 "provider not available, disabling JIT for current session");
97 return false;
98 }
99
100 /*
101 * If loading functions fails, signal failure. We do so because
102 * load_external_function() might error out despite the above check if
103 * e.g. the library's dependencies aren't installed. We want to signal
104 * ERROR in that case, so the user is notified, but we don't want to
105 * continually retry.
106 */
108
109 /* and initialize */
111 load_external_function(path, "_PG_jit_provider_init", true, NULL);
112 init(&provider);
113
116
117 elog(DEBUG1, "successfully loaded JIT provider in current session");
118
119 return true;
120}
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:95
#define DEBUG1
Definition: elog.h:30
#define elog(elevel,...)
Definition: elog.h:225
bool pg_file_exists(const char *name)
Definition: fd.c:502
char pkglib_path[MAXPGPATH]
Definition: globals.c:81
int init
Definition: isn.c:74
bool jit_enabled
Definition: jit.c:32
char * jit_provider
Definition: jit.c:33
static bool provider_failed_loading
Definition: jit.c:45
void(* JitProviderInit)(JitProviderCallbacks *cb)
Definition: jit.h:68
#define MAXPGPATH
#define snprintf
Definition: port.h:238

References DEBUG1, elog, init, jit_enabled, jit_provider, load_external_function(), MAXPGPATH, pg_file_exists(), pkglib_path, provider, provider_failed_loading, provider_successfully_loaded, and snprintf.

Referenced by jit_compile_expr(), and pg_jit_available().

Variable Documentation

◆ jit_above_cost

double jit_above_cost = 100000

Definition at line 39 of file jit.c.

Referenced by standard_planner().

◆ jit_debugging_support

bool jit_debugging_support = false

Definition at line 34 of file jit.c.

Referenced by llvm_create_object_layer().

◆ jit_dump_bitcode

bool jit_dump_bitcode = false

Definition at line 35 of file jit.c.

Referenced by llvm_compile_module().

◆ jit_enabled

bool jit_enabled = true

Definition at line 32 of file jit.c.

Referenced by provider_init(), and standard_planner().

◆ jit_expressions

bool jit_expressions = true

Definition at line 36 of file jit.c.

Referenced by standard_planner().

◆ jit_inline_above_cost

double jit_inline_above_cost = 500000

Definition at line 40 of file jit.c.

Referenced by standard_planner().

◆ jit_optimize_above_cost

double jit_optimize_above_cost = 500000

Definition at line 41 of file jit.c.

Referenced by standard_planner().

◆ jit_profiling_support

bool jit_profiling_support = false

Definition at line 37 of file jit.c.

Referenced by llvm_create_object_layer().

◆ jit_provider

char* jit_provider = NULL

Definition at line 33 of file jit.c.

Referenced by provider_init().

◆ jit_tuple_deforming

bool jit_tuple_deforming = true

Definition at line 38 of file jit.c.

Referenced by standard_planner().

◆ provider

◆ provider_failed_loading

bool provider_failed_loading = false
static

Definition at line 45 of file jit.c.

Referenced by provider_init().

◆ provider_successfully_loaded

bool provider_successfully_loaded = false
static

Definition at line 44 of file jit.c.

Referenced by jit_release_context(), jit_reset_after_error(), and provider_init().