Skip to content
Permalink
Browse files
First rough version of the JIT.
It can successfully parse SpeedMessage1.
Preliminary results: 750MB/s on Core2 2.4GHz.
This number is 2.5x proto2.
This isn't apples-to-apples, because
proto2 is parsing to a struct and we are
just doing stream parsing, but for apps
that are currently using proto2, this is the
improvement they would see if they could
move to stream-based processing.

Unfortunately perf-regression-test.py is
broken, and I'm not 100% sure why.  It would
be nice to fix it first (to ensure that
there are no performance regressions for
the table-based decoder) but I'm really
impatient to get the JIT checked in.
  • Loading branch information
Joshua Haberman committed Apr 1, 2011
1 parent 19517cc commit 9eb4d69
Show file tree
Hide file tree
Showing 30 changed files with 7,589 additions and 402 deletions.
@@ -38,7 +38,7 @@ endif
# Basic compiler/flag setup.
CC=gcc
CXX=g++
CFLAGS=-std=c99
CFLAGS=-std=gnu99
INCLUDE=-Isrc -Itests -I.
CPPFLAGS=$(INCLUDE) -Wall -Wextra $(USER_CFLAGS)
LDLIBS=-lpthread src/libupb.a
@@ -86,9 +86,6 @@ STREAM= \
src/upb_strstream.c \
src/upb_glue.c \

ASMCORE= \
src/upb_decoder_x64.asm

# Parts of core that are yet to be converted.
OTHERSRC=src/upb_encoder.c

@@ -115,7 +112,10 @@ ALLSRC=$(CORE) $(STREAM) $(BENCHMARKS_SRC) $(TESTS_SRC)
clean_leave_profile:
rm -rf $(LIBUPB) $(LIBUPB_PIC)
rm -rf $(call rwildcard,,*.o) $(call rwildcard,,*.lo) $(call rwildcard,,*.dSYM)
rm -rf src/upb_decoder_x86.h
rm -rf benchmark/google_messages.proto.pb benchmark/google_messages.pb.* benchmarks/b.* benchmarks/*.pb*
rm -rf src/jit_debug_elf_file.o
rm -rf src/jit_debug_elf_file.h
rm -rf $(TESTS) tests/t.*
rm -rf src/descriptor.pb
rm -rf src/upbc deps
@@ -135,9 +135,11 @@ lib: $(LIBUPB)
OBJ=$(patsubst %.c,%.o,$(SRC))
PICOBJ=$(patsubst %.c,%.lo,$(SRC))

ifneq (, $(findstring DUSE_X64_FASTPATH, $(USER_CFLAGS)))
OBJ += src/upb_decoder_x64.o
PICOBJ += src/upb_decoder_x64.o
ifneq (, $(findstring DUPB_USE_JIT_X64, $(USER_CFLAGS)))
src/upb_decoder.o: src/upb_decoder_x86.h
ifeq (, $(findstring DNDEBUG, $(USER_CFLAGS)))
$(error "JIT only works with -DNDEBUG enabled!")
endif
endif
$(LIBUPB): $(OBJ)
$(E) AR $(LIBUPB)
@@ -164,13 +166,18 @@ src/upb_def.lo: src/upb_def.c
$(E) 'CC -fPIC' $<
$(Q) $(CC) $(CFLAGS) $(CPPFLAGS) $(DEF_OPT) -c -o $@ $< -fPIC

src/upb_decoder_x64.o: src/upb_decoder_x64.asm
$(E) NASM $<
$(Q) nasm -Ox src/upb_decoder_x64.asm -o src/upb_decoder_x64.o -f macho64
src/upb_decoder_x86.h: src/jit_debug_elf_file.h
src/upb_decoder_x86.h: src/upb_decoder_x86.dasc
$(E) DYNASM $<
$(Q) lua dynasm/dynasm.lua src/upb_decoder_x86.dasc > src/upb_decoder_x86.h

src/jit_debug_elf_file.o: src/jit_debug_elf_file.s
$(E) GAS $<
$(Q) gcc -c src/jit_debug_elf_file.s -o src/jit_debug_elf_file.o

src/upb_decoder_x64.lo: src/upb_decoder_x64.asm
$(E) NASM $<
$(Q) nasm -Ox src/upb_decoder_x64.asm -o src/upb_decoder_x64.lo -f macho64
src/jit_debug_elf_file.h: src/jit_debug_elf_file.o
$(E) XXD $<
$(Q) xxd -i src/jit_debug_elf_file.o > src/jit_debug_elf_file.h

# Function to expand a wildcard pattern recursively.
rwildcard=$(strip $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)$(filter $(subst *,%,$2),$d)))
@@ -12,6 +12,19 @@ static upb_decoder decoder;
static upb_stringsrc stringsrc;
upb_handlers handlers;

static upb_sflow_t startsubmsg(void *_m, upb_value fval) {
(void)_m;
(void)fval;
return UPB_CONTINUE_WITH(NULL);
}

static upb_flow_t value(void *closure, upb_value fval, upb_value val) {
(void)closure;
(void)fval;
(void)val;
return UPB_CONTINUE;
}

static bool initialize()
{
// Initialize upb state, decode descriptor.
@@ -50,7 +63,7 @@ static bool initialize()

upb_handlers_init(&handlers, def);
// Cause all messages to be read, but do nothing when they are.
upb_register_all(&handlers, NULL, NULL, NULL, NULL, NULL, NULL);
upb_register_all(&handlers, NULL, NULL, value, startsubmsg, NULL, NULL);
upb_decoder_init(&decoder, &handlers);
upb_stringsrc_init(&stringsrc);
return true;
@@ -62,7 +75,6 @@ static void cleanup()
upb_def_unref(UPB_UPCAST(def));
upb_decoder_uninit(&decoder);
upb_stringsrc_uninit(&stringsrc);
upb_handlers_uninit(&handlers);
}

static size_t run(int i)
@@ -78,7 +78,6 @@ static void cleanup()
upb_def_unref(UPB_UPCAST(def));
upb_stringsrc_uninit(&strsrc);
upb_decoder_uninit(&d);
upb_handlers_uninit(&h);
}

static size_t run(int i)
@@ -0,0 +1,58 @@
DynASM is taken from LuaJIT 2, which carries the following license statement:

===============================================================================
LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/

Copyright (C) 2005-2011 Mike Pall. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

[ MIT license: http://www.opensource.org/licenses/mit-license.php ]

===============================================================================
[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]

Copyright (C) 1994-2011 Lua.org, PUC-Rio.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

===============================================================================
[ LuaJIT includes code from dlmalloc, which has this license statement: ]

This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain, as explained at
http://creativecommons.org/licenses/publicdomain

===============================================================================

0 comments on commit 9eb4d69

Please sign in to comment.