Ticket #180: librun-dtrace.patch
File librun-dtrace.patch, 12.0 KB (added by , 7 years ago) |
---|
-
Make.proto
diff -r 34b43cd6cff1 Make.proto
a b 20 20 EFENCE_OBJS= 21 21 USE_EFENCE= 22 22 23 DTRACE=dtrace 24 DTRACEFLAGS= 23 25 #--------- no need to modify anything below ------- 24 26 25 27 TOP=.. … … 45 47 CFLAGS=-g -fdiagnostics-color=auto -fwrapv -Wall -W -Wno-unused-parameter -Wno-error=unused-variable -Wno-comment -Wno-error=comment -I$(INCLUDE) $(OS) $(LIBRUN_OPT) $(CFLAGS_1) $(OPT_1) $(USE_EFENCE) $(DEBUG_OPTIONS) 46 48 CPPFLAGS=-I$(INCLUDE) $(OS) $(CFLAGS_1) 47 49 50 51 DTRACE_SRCS=probes.d 52 DTRACE_OBJS=$(patsubst %.d,%.o,$(DTRACE_SRCS)) 53 DTRACE_HDRS=$(patsubst %.d,%.h,$(DTRACE_SRCS)) 54 48 55 SRCS = errhandler.c stxmain.c init.c classes.c lookup.c backtrace.c \ 49 56 new.c send.c snapshot.c process.c stack.c \ 50 57 char.c float.c string.c symbol.c globals.c \ 51 58 util.c interrupt.c statistic.c interpret.c stxplugin.c \ 52 main.c memory.c md5.c jinterpret.c malloc.c symlist.c $(EFENCE_SRC) 59 main.c memory.c md5.c jinterpret.c malloc.c symlist.c $(EFENCE_SRC) \ 60 $(DTRACE_SRCS) 53 61 54 62 #ASM = asmhelp.$(O) codeproto.$(O) 55 63 ASM = asmhelp.$(O) … … 59 67 CHAR FLOAT STRING SYMBOL GLOBALS \ 60 68 UTIL INTERRUPT STATISTIC INTERPRET \ 61 69 ASMHELP MCOMPILER MEMORY STXMAIN MD5 JINTERPRET \ 62 STXPLUGIN MALLOC symlist.$(O) $(LIBFFI_OBJS) 70 STXPLUGIN MALLOC symlist.$(O) $(LIBFFI_OBJS) \ 71 $(DTRACE_OBJS) 63 72 64 73 STX_LIBRUN_OBJS = \ 65 74 errhandler.$(O) init.$(O) classes.$(O) lookup.$(O) \ … … 67 76 send.$(O) process.$(O) stack.$(O) \ 68 77 char.$(O) float.$(O) string.$(O) symbol.$(O) globals.$(O) \ 69 78 util.$(O) interrupt.$(O) statistic.$(O) interpret.$(O) \ 70 jinterpret.$(O) mcompiler.$(O) memory.$(O) stxplugin.$(O) stxmain.$(O) 79 jinterpret.$(O) mcompiler.$(O) memory.$(O) stxplugin.$(O) stxmain.$(O) \ 80 $(DTRACE_OBJS) 71 81 72 82 BINARY_ONLY_OBJS = \ 73 83 $(STX_LIBRUN_OBJS) \ … … 81 91 DUMPIMAGE_OBJS = $(BINARY_ONLY_OBJS) $(SOURCE_OBJS) 82 92 OBJS = $(DUMPIMAGE_OBJS) snapshot.$(O) 83 93 84 HDR = $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h $(CPUINTERN_H) 94 HDR = $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h $(CPUINTERN_H) $(DTRACE_HDRS) 85 95 86 96 all:: copiedHeaderFiles 87 97 @if [ ! -f new.c ]; then \ … … 95 105 Makefiles:: $(LIBFFI_DIR)/build/Makefile 96 106 97 107 98 $(LIBFFI_DIR)/build/Makefile: 108 $(LIBFFI_DIR)/build/Makefile: 99 109 mkdir -p $(LIBFFI_DIR)/build 100 110 cd $(LIBFFI_DIR)/build && CC=$(FFI_CC) LD=$(FFI_LD) CFLAGS=$(FFI_CFLAGS) ../configure 101 111 … … 111 121 cleanFFI: 112 122 if [ -d $(LIBFFI_DIR)/build ]; then \ 113 123 $(MAKE) -C $(LIBFFI_DIR)/build clean; \ 114 fi 124 fi 115 125 116 126 clean:: cleanFFI 117 127 … … 194 204 fi; \ 195 205 done 196 206 197 clean:: cleanOBJS cleanTAGS 207 cleanProbes: 208 rm -rf $(DTRACE_OBJS) $(DTRACE_HDRS) 209 210 clean:: cleanOBJS cleanTAGS cleanProbes 198 211 -rm -f asmhelp.s codeproto.s interpret.[Ss] *.timestamp 199 212 @-if [ -d VGL/vogl ]; then \ 200 213 cd VGL/vogl && rm -f drivers/*.o src/*.o; \ … … 460 473 fi; \ 461 474 fi 462 475 476 probes.h: probes.d 477 CC="$(LIBRUN_CC)" CFLAGS="$(CCCONFOPT)" $(DTRACE) $(DTRACEFLAGS) -h -s $< -o $@ 478 479 probes.o: probes.d 480 CC="$(LIBRUN_CC)" CFLAGS="$(CCCONFOPT)" $(DTRACE) $(DTRACEFLAGS) -G -s $< -o $@ 481 463 482 464 483 # 465 484 # generate a symbols.h file from the symbols.stc file. … … 479 498 ln -s ../librun/mcompiler.h $(INCLUDE)/mcompiler.h 480 499 481 500 482 $(OBJS): $(HDR) 501 $(OBJS): $(HDR) 483 502 484 503 # 485 504 # special edit-scripts to patch intermediate assembler output … … 597 616 AIX2:: 598 617 $(MAKE) aixPhase2 OPT=-O2 LIBRUN_SPECIAL_OPT=-O2 599 618 600 aixPhase2: 619 aixPhase2: 601 620 $(MAKE) LIBRUN_CC=$(LIBRUN_CC) CC="$(CC)" OPT="$(OPT)" 602 621 603 622 aix:: … … 650 669 interpret.$(O): bytecodes.h 651 670 jinterpret.$(O): jbytecodes.h 652 671 mcompiler.$(O): bytecodes.h $(CPUINTERN_H) 653 classes.$(O): $(INCLUDE)/stcVMdata.h md5.h 672 classes.$(O): $(INCLUDE)/stcVMdata.h md5.h 654 673 globals.$(O): $(INCLUDE)/stcVMdata.h 655 674 new.$(O): $(INCLUDE)/stcVMdata.h symbols.h 656 675 snapshot.$(O): $(INCLUDE)/stcVMdata.h … … 791 810 792 811 ubsan: 793 812 $(MAKE) LIBRUN_OPT="-ggdb3 -O -fsanitize=undefined -fno-stack-protector -fomit-frame-pointer -fPIC" snapshot.o symbol.o 794 $(MAKE) LIBRUN_OPT="-ggdb3 -O0 -fsanitize=undefined -fno-stack-protector -fomit-frame-pointer -fPIC" 813 $(MAKE) LIBRUN_OPT="-ggdb3 -O0 -fsanitize=undefined -fno-stack-protector -fomit-frame-pointer -fPIC" 795 814 $(LIBRUN_CC) $(NOSTDLIB) -shared $(LDFLAGS) -fsanitize=undefined -o librun$(SO_NAME) $(OBJS) $(LOCAL_SHARED_LIBS) $(EXTRA_SHARED_LIBS) -lubsan 796 815 797 816 -
jsupport.h
diff -r 34b43cd6cff1 jsupport.h
a b 1 /* 1 /* 2 2 * Copyright (c) 2016-now Jan Vrany 3 * 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining 5 5 * a copy of this software and associated documentation files (the 6 6 * "Software"), to deal in the Software without restriction, including … … 8 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 9 * permit persons to whom the Software is furnished to do so, subject to 10 10 * the following conditions: 11 * 11 * 12 12 * The above copyright notice and this permission notice shall be 13 13 * included in all copies or substantial portions of the Software. 14 * 14 * 15 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 17 * MeERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. … … 55 55 if ( stxThinUnlock( stxGetLockwordPtr(o) ) == StxThinlockSuccess ) { 56 56 return; 57 57 } 58 #endif 59 { 58 #endif 59 { 60 60 static struct inlineCache ilc_MONITOREXIT = __ILC1(0); 61 61 static OBJ sym_MONITOREXIT = (OBJ)0; 62 62 if (sym_MONITOREXIT == (OBJ)0) { -
new file librun.stp
diff -r 34b43cd6cff1 librun.stp
- + 1 /* 2 * Copyright (c) 2016-now Jan Vrany 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 * permit persons to whom the Software is furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MeERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 /** 25 * SystemTap probe library for Smalltalk/X VM. 26 */ 27 @define librun %( process.library("librun.so") %) 28 29 /** 30 * 31 */ 32 probe stx.process.create = @librun.mark("process_create") { } 33 34 probe stx.process.switch = @librun.mark("process_switch") { } 35 36 probe stx.process.destroy = @librun.mark("process_destroy") { } 37 38 -
new file probes.d
diff -r 34b43cd6cff1 probes.d
- + 1 provider stx { 2 probe process_create(uintptr_t pid); 3 probe process_switch(uintptr_t pid); 4 probe process_destroy(uintptr_t pid); 5 } -
process.c
diff -r 34b43cd6cff1 process.c
a b 65 65 * __initProcess() - called very early (before any smalltalk activity) 66 66 * should setup the init-thread 67 67 * 68 * __threadCreate( block) - to create a new (unscheduled) thread evaluating block69 * return an integer id68 * __threadCreate(p, stackSize, pId) - to create a new (unscheduled) thread 69 * evaluating block return an integer id 70 70 * 71 71 * __threadSwitch(pId) - give control to process with id pId 72 72 * … … 113 113 114 114 #include "runtime.h" 115 115 #include "stxprocess.h" 116 #include "process-probes.h" 116 117 #include "thinlocks.h" 117 118 119 118 120 #ifdef APIWRAPTHREADS 119 121 # include "apithreads.h" 120 122 #endif … … 145 147 146 148 /* 147 149 * A temporary static global variable to hold process to be run 148 * for a short period in `____threadSwitch()` between stack is switched 150 * for a short period in `____threadSwitch()` between stack is switched 149 151 * and stxStartProcess() is called. This hack is needed since after 150 * switching stack, all local variables of `____threadSwitch()` are gone. 151 * 152 * switching stack, all local variables of `____threadSwitch()` are gone. 153 * 152 154 * See `____threadSwitch()` 153 155 * 154 156 * BEWARE, that we have to make sure compiler does not optimize it away, 155 157 * it can legaaly do it! See C99 Spec, Section 6.7.3 Type qualifiers: 156 158 * 157 * What constitutes an access to an object that has volatile-qualified 158 * type is implementation-defined. 159 * What constitutes an access to an object that has volatile-qualified 160 * type is implementation-defined. 159 161 * 160 162 */ 161 static VOLATILE 163 static VOLATILE 162 164 struct process *__processToRun = NULL; 163 165 164 166 #define PROCCHUNKSIZE 20 … … 343 345 } 344 346 345 347 #if !defined(POSITIVE_ADDRESSES) && !defined(NEGATIVE_ADDRESSES) 346 # define MKIDTL(id) ((id << STX_LOCKWORD_PID_SHIFT) | TAG_INT) 348 # define MKIDTL(id) ((id << STX_LOCKWORD_PID_SHIFT) | TAG_INT) 347 349 #else 348 350 # error "Don't know how to construct IDTL (process ID for thinlocks) on this platform" 349 #endif 351 #endif 350 352 351 353 /* 352 354 * allocate a chunk of process structures … … 1800 1802 /* 1801 1803 * Following code is hare only to prevent compiler from optimizing 1802 1804 * away __processToRun. Even though it's declared volatile, compiler 1803 * may discard it, see comment before `__processToRun` declaration. 1805 * may discard it, see comment before `__processToRun` declaration. 1804 1806 * 1805 * As for GCC, we have to both write and __read__ the variable, 1807 * As for GCC, we have to both write and __read__ the variable, 1806 1808 * otherwise it optimizes it away. So: 1807 */ 1809 */ 1808 1810 if ((void*)__processToRun == (void*)1/* it's pointer */) { 1809 1811 __processToRun = NULL; 1810 1812 } … … 2157 2159 __threadCreate(OBJ process, int stackSize, INT id) 2158 2160 { 2159 2161 struct process *p; 2162 INT pid; 2160 2163 2161 2164 p = newProc(id); 2162 2165 if (! p) { … … 2169 2172 __processes__ = p; 2170 2173 2171 2174 SDPRINTF(("VM threadCreate %"_ld_" returns ok %"_ld_"\n", id, p->id)); 2175 pid = p->id; 2176 STX_PROCESS_CREATE(pid); 2172 2177 return p->id; 2173 2178 } 2174 2179 … … 2244 2249 } 2245 2250 2246 2251 processToRun = __getProcessFromID(processId); 2252 STX_PROCESS_SWITCH(processId); 2247 2253 if (!processToRun) { 2248 2254 SDPRINTF(("VM [warning]: no process with id %d in threadSwitch\n", processId)); 2249 2255 return false; … … 2671 2677 __currentNativeProcess = activeProcess; 2672 2678 #endif 2673 2679 __currentProcess = activeProcess; 2674 __activeProcessIdtl = MKIDTL(activeProcess->id); 2680 __activeProcessIdtl = MKIDTL(activeProcess->id); 2675 2681 __thisContext = activeProcess->context; 2676 2682 #ifdef STACK_GROWS_UPWARD 2677 2683 __stackTop__ = activeProcess->stackTop; … … 2937 2943 return ____threadSwitch(aContext, processId, withSingleStep, callerLine, THREADSWITCH_NO_DEBUG); 2938 2944 } 2939 2945 2940 2941 2946 void 2942 2947 __threadDestroy(INT id) 2943 2948 { … … 2946 2951 SDPRINTF(("[info]: destroy 1 %"_ld_" (%"_ld_")\n", id, __currentProcess->id)); 2947 2952 2948 2953 p = __getProcessFromID(id); 2954 STX_PROCESS_DESTROY(id); 2949 2955 if (! p || (p == __currentProcess)) { 2950 2956 DPRINTF(("tried to destroy null or current process\n")); 2951 2957 return; -
stxprocess.h
diff -r 34b43cd6cff1 stxprocess.h
a b 114 114 # define InitializeLongCriticalSection(pMutex) pthread_mutex_init(pMutex, NULL) 115 115 # else 116 116 # if defined(NATIVETHREADS) || defined(APIWRAPTHREADS) 117 # error : must define mutex primitives117 # error "must define mutex primitives" 118 118 # else 119 119 # define EnterShortCriticalSection(sect) /* nothing */ 120 120 # define LeaveShortCriticalSection(sect) /* nothing */