Faculty of Information Technology
Software Engineering Group

Ticket #180: librun-dtrace.patch

File librun-dtrace.patch, 12.0 KB (added by Jan Vrany, 4 years ago)
  • Make.proto

    diff -r 34b43cd6cff1 Make.proto
    a b  
    2020EFENCE_OBJS=
    2121USE_EFENCE=
    2222
     23DTRACE=dtrace
     24DTRACEFLAGS=
    2325#--------- no need to modify anything below -------
    2426
    2527TOP=..
     
    4547CFLAGS=-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)
    4648CPPFLAGS=-I$(INCLUDE) $(OS) $(CFLAGS_1)
    4749
     50
     51DTRACE_SRCS=probes.d
     52DTRACE_OBJS=$(patsubst %.d,%.o,$(DTRACE_SRCS))
     53DTRACE_HDRS=$(patsubst %.d,%.h,$(DTRACE_SRCS))
     54
    4855SRCS =  errhandler.c stxmain.c init.c classes.c lookup.c backtrace.c \
    4956        new.c send.c snapshot.c process.c stack.c \
    5057        char.c float.c string.c symbol.c globals.c      \
    5158        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)
    5361
    5462#ASM =    asmhelp.$(O) codeproto.$(O)
    5563ASM =    asmhelp.$(O)
     
    5967         CHAR FLOAT STRING SYMBOL GLOBALS   \
    6068         UTIL INTERRUPT STATISTIC INTERPRET \
    6169         ASMHELP MCOMPILER MEMORY STXMAIN MD5 JINTERPRET \
    62          STXPLUGIN MALLOC symlist.$(O) $(LIBFFI_OBJS)
     70         STXPLUGIN MALLOC symlist.$(O) $(LIBFFI_OBJS) \
     71         $(DTRACE_OBJS)
    6372
    6473STX_LIBRUN_OBJS = \
    6574        errhandler.$(O) init.$(O) classes.$(O) lookup.$(O) \
     
    6776        send.$(O) process.$(O) stack.$(O) \
    6877        char.$(O) float.$(O) string.$(O) symbol.$(O) globals.$(O)  \
    6978        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)
    7181
    7282BINARY_ONLY_OBJS = \
    7383        $(STX_LIBRUN_OBJS) \
     
    8191DUMPIMAGE_OBJS = $(BINARY_ONLY_OBJS) $(SOURCE_OBJS)
    8292OBJS =           $(DUMPIMAGE_OBJS) snapshot.$(O)
    8393
    84 HDR  = $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h $(CPUINTERN_H)
     94HDR  = $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h $(CPUINTERN_H) $(DTRACE_HDRS)
    8595
    8696all::   copiedHeaderFiles
    8797        @if [ ! -f new.c ]; then \
     
    95105Makefiles:: $(LIBFFI_DIR)/build/Makefile
    96106
    97107
    98 $(LIBFFI_DIR)/build/Makefile: 
     108$(LIBFFI_DIR)/build/Makefile:
    99109        mkdir -p $(LIBFFI_DIR)/build
    100110        cd $(LIBFFI_DIR)/build && CC=$(FFI_CC) LD=$(FFI_LD) CFLAGS=$(FFI_CFLAGS) ../configure
    101111
     
    111121cleanFFI:
    112122        if [ -d $(LIBFFI_DIR)/build ]; then \
    113123            $(MAKE) -C $(LIBFFI_DIR)/build clean; \
    114         fi         
     124        fi
    115125
    116126clean:: cleanFFI
    117127
     
    194204            fi; \
    195205        done
    196206
    197 clean:: cleanOBJS cleanTAGS     
     207cleanProbes:
     208        rm -rf $(DTRACE_OBJS) $(DTRACE_HDRS)
     209
     210clean:: cleanOBJS cleanTAGS cleanProbes
    198211        -rm -f asmhelp.s codeproto.s interpret.[Ss] *.timestamp
    199212        @-if [ -d VGL/vogl ]; then                               \
    200213            cd VGL/vogl && rm -f drivers/*.o src/*.o;           \
     
    460473            fi; \
    461474        fi
    462475
     476probes.h: probes.d
     477        CC="$(LIBRUN_CC)" CFLAGS="$(CCCONFOPT)" $(DTRACE) $(DTRACEFLAGS) -h -s $< -o $@
     478
     479probes.o: probes.d
     480        CC="$(LIBRUN_CC)" CFLAGS="$(CCCONFOPT)" $(DTRACE) $(DTRACEFLAGS) -G -s $< -o $@
     481
    463482
    464483#
    465484# generate a symbols.h file from the symbols.stc file.
     
    479498        ln -s ../librun/mcompiler.h $(INCLUDE)/mcompiler.h
    480499
    481500
    482 $(OBJS): $(HDR) 
     501$(OBJS): $(HDR)
    483502
    484503#
    485504# special edit-scripts to patch intermediate assembler output
     
    597616AIX2::
    598617                $(MAKE) aixPhase2 OPT=-O2 LIBRUN_SPECIAL_OPT=-O2
    599618
    600 aixPhase2: 
     619aixPhase2:
    601620                $(MAKE) LIBRUN_CC=$(LIBRUN_CC) CC="$(CC)" OPT="$(OPT)"
    602621
    603622aix::
     
    650669interpret.$(O): bytecodes.h
    651670jinterpret.$(O): jbytecodes.h
    652671mcompiler.$(O): bytecodes.h $(CPUINTERN_H)
    653 classes.$(O):   $(INCLUDE)/stcVMdata.h md5.h 
     672classes.$(O):   $(INCLUDE)/stcVMdata.h md5.h
    654673globals.$(O):   $(INCLUDE)/stcVMdata.h
    655674new.$(O):       $(INCLUDE)/stcVMdata.h symbols.h
    656675snapshot.$(O):  $(INCLUDE)/stcVMdata.h
     
    791810
    792811ubsan:
    793812        $(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"
    795814        $(LIBRUN_CC) $(NOSTDLIB) -shared $(LDFLAGS) -fsanitize=undefined -o librun$(SO_NAME) $(OBJS) $(LOCAL_SHARED_LIBS) $(EXTRA_SHARED_LIBS) -lubsan
    796815
    797816
  • jsupport.h

    diff -r 34b43cd6cff1 jsupport.h
    a b  
    1 /* 
     1/*
    22 * Copyright (c) 2016-now Jan Vrany
    3  * 
     3 *
    44 * Permission is hereby granted, free of charge, to any person obtaining
    55 * a copy of this software and associated documentation files (the
    66 * "Software"), to deal in the Software without restriction, including
     
    88 * distribute, sublicense, and/or sell copies of the Software, and to
    99 * permit persons to whom the Software is furnished to do so, subject to
    1010 * the following conditions:
    11  * 
     11 *
    1212 * The above copyright notice and this permission notice shall be
    1313 * included in all copies or substantial portions of the Software.
    14  * 
     14 *
    1515 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1616 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1717 * MeERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     
    5555    if ( stxThinUnlock( stxGetLockwordPtr(o) ) == StxThinlockSuccess ) {
    5656        return;
    5757    }
    58 #endif 
    59     {   
     58#endif
     59    {
    6060        static struct inlineCache ilc_MONITOREXIT = __ILC1(0);
    6161        static OBJ                sym_MONITOREXIT = (OBJ)0;
    6262        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 */
     32probe stx.process.create = @librun.mark("process_create") {  }
     33
     34probe stx.process.switch = @librun.mark("process_switch") { }
     35
     36probe stx.process.destroy = @librun.mark("process_destroy") {  }
     37
     38
  • new file probes.d

    diff -r 34b43cd6cff1 probes.d
    - +  
     1provider 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  
    6565 * __initProcess()          - called very early (before any smalltalk activity)
    6666 *                          should setup the init-thread
    6767 *
    68  * __threadCreate(block)  - to create a new (unscheduled) thread evaluating block
    69  *                          return an integer id
     68 * __threadCreate(p, stackSize, pId) - to create a new (unscheduled) thread
     69 *                         evaluating block return an integer id
    7070 *
    7171 * __threadSwitch(pId)    - give control to process with id pId
    7272 *
     
    113113
    114114#include "runtime.h"
    115115#include "stxprocess.h"
     116#include "process-probes.h"
    116117#include "thinlocks.h"
    117118
     119
    118120#ifdef APIWRAPTHREADS
    119121# include "apithreads.h"
    120122#endif
     
    145147
    146148/*
    147149 * 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
    149151 * 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 *
    152154 * See `____threadSwitch()`
    153155 *
    154156 * BEWARE, that we have to make sure compiler does not optimize it away,
    155157 * it can legaaly do it! See C99 Spec, Section 6.7.3 Type qualifiers:
    156158 *
    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.
    159161 *
    160162 */
    161 static VOLATILE 
     163static VOLATILE
    162164struct process *__processToRun = NULL;
    163165
    164166#define PROCCHUNKSIZE       20
     
    343345  }
    344346
    345347#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)
    347349#else
    348350#       error "Don't know how to construct IDTL (process ID for thinlocks) on this platform"
    349 #endif   
     351#endif
    350352
    351353/*
    352354 * allocate a chunk of process structures
     
    18001802        /*
    18011803         * Following code is hare only to prevent compiler from optimizing
    18021804         * 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.
    18041806         *
    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,
    18061808         * otherwise it optimizes it away. So:
    1807          */ 
     1809         */
    18081810        if ((void*)__processToRun == (void*)1/* it's pointer */) {
    18091811            __processToRun = NULL;
    18101812        }
     
    21572159__threadCreate(OBJ process, int stackSize, INT id)
    21582160{
    21592161        struct process *p;
     2162        INT pid;
    21602163
    21612164        p = newProc(id);
    21622165        if (! p) {
     
    21692172        __processes__ = p;
    21702173
    21712174        SDPRINTF(("VM threadCreate %"_ld_" returns ok %"_ld_"\n", id, p->id));
     2175        pid = p->id;
     2176        STX_PROCESS_CREATE(pid);
    21722177        return p->id;
    21732178}
    21742179
     
    22442249        }
    22452250
    22462251        processToRun = __getProcessFromID(processId);
     2252        STX_PROCESS_SWITCH(processId);
    22472253        if (!processToRun) {
    22482254            SDPRINTF(("VM [warning]: no process with id %d in threadSwitch\n", processId));
    22492255            return false;
     
    26712677    __currentNativeProcess = activeProcess;
    26722678#endif
    26732679    __currentProcess = activeProcess;
    2674     __activeProcessIdtl = MKIDTL(activeProcess->id);   
     2680    __activeProcessIdtl = MKIDTL(activeProcess->id);
    26752681    __thisContext = activeProcess->context;
    26762682#ifdef STACK_GROWS_UPWARD
    26772683    __stackTop__ = activeProcess->stackTop;
     
    29372943    return ____threadSwitch(aContext, processId, withSingleStep, callerLine, THREADSWITCH_NO_DEBUG);
    29382944}
    29392945
    2940 
    29412946void
    29422947__threadDestroy(INT id)
    29432948{
     
    29462951        SDPRINTF(("[info]: destroy 1 %"_ld_" (%"_ld_")\n", id, __currentProcess->id));
    29472952
    29482953        p = __getProcessFromID(id);
     2954        STX_PROCESS_DESTROY(id);
    29492955        if (! p || (p == __currentProcess)) {
    29502956            DPRINTF(("tried to destroy null or current process\n"));
    29512957            return;
  • stxprocess.h

    diff -r 34b43cd6cff1 stxprocess.h
    a b  
    114114#  define InitializeLongCriticalSection(pMutex) pthread_mutex_init(pMutex, NULL)
    115115# else
    116116#  if defined(NATIVETHREADS) || defined(APIWRAPTHREADS)
    117 #    error: must define mutex primitives
     117#    error "must define mutex primitives"
    118118#  else
    119119#   define EnterShortCriticalSection(sect)      /* nothing */
    120120#   define LeaveShortCriticalSection(sect)      /* nothing */