Skip to content

Commit

Permalink
Merge pull request #81 from tesonep/feature/merge-new-threadedFFI-ver…
Browse files Browse the repository at this point in the history
…sion

merge-new-threadedFFI-version
  • Loading branch information
tesonep authored Apr 30, 2020
2 parents 7d8264d + 46c03a9 commit fecd981
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 53 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_policy(SET CMP0053 NEW)
include(macros.cmake)

set(VERSION_MAJOR 8)
set(VERSION_MINOR 3)
set(VERSION_MINOR 4)
set(VERSION_PATCH 0)

set(APPNAME Pharo CACHE STRING "VM Application name")
Expand Down Expand Up @@ -242,7 +242,6 @@ add_custom_command(
OUTPUT ${VMMAKER_OUTPUT_PATH}/VMMaker.image
COMMAND ./pharo Pharo.image --save --quit ${CMAKE_CURRENT_SOURCE_DIR_TO_OUT}/scripts/installVMMaker.st ${CMAKE_CURRENT_SOURCE_DIR_TO_OUT}
COMMAND ./pharo Pharo.image save VMMaker --delete-old
MAIN_DEPENDENCY ${VMMAKER_OUTPUT_PATH}/Pharo.image
DEPENDS ${VMMAKER_OUTPUT_PATH}/Pharo.image
WORKING_DIRECTORY ${VMMAKER_OUTPUT_PATH}
COMMENT "Generating VMMaker image")
Expand All @@ -251,7 +250,7 @@ COMMENT "Generating VMMaker image")
add_custom_command(
OUTPUT ${VMSOURCEFILES}
COMMAND ${VMMAKER_OUTPUT_PATH}/pharo ${VMMAKER_OUTPUT_PATH}/VMMaker.image eval \"PharoVMMaker generate: \#\'${FLAVOUR}\' outputDirectory: \'${CMAKE_CURRENT_BINARY_DIR_TO_OUT}\'\"
MAIN_DEPENDENCY ${VMMAKER_OUTPUT_PATH}/VMMaker.image
DEPENDS ${VMMAKER_OUTPUT_PATH}/VMMaker.image
COMMENT "Generating VM files for flavour: ${FLAVOUR}")

#Generating config file
Expand All @@ -264,6 +263,7 @@ message(STATUS "Resource Compiler: ${CMAKE_RC_COMPILER}")

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/semaphores
${CMAKE_CURRENT_BINARY_DIR}/build/include/
${CMAKE_CURRENT_BINARY_DIR}/build/include/pharovm/
${CMAKE_CURRENT_BINARY_DIR}/generated/vm/include
Expand Down Expand Up @@ -293,6 +293,7 @@ set(SUPPORT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/fileDialogCommon.c
${CMAKE_CURRENT_SOURCE_DIR}/src/stringUtilities.c
${CMAKE_CURRENT_SOURCE_DIR}/src/imageAccess.c
${CMAKE_CURRENT_SOURCE_DIR}/src/semaphores/platformSemaphore.c
)

set(VM_SOURCES
Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def runTests(platform, configuration, packages){

shell "mkdir runTests"
dir("runTests"){
shell "wget -O - get.pharo.org/64/80 | bash "
shell "echo 80 > pharo.version"
shell "wget -O - get.pharo.org/64/90 | bash "
shell "echo 90 > pharo.version"

if(isWindows()){
runInCygwin "cd runTests && unzip ../build/build/packages/PharoVM-*-${vmDir}64-bin.zip -d ."
Expand Down
25 changes: 8 additions & 17 deletions extracted/vm/include/common/sq.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#define false 0
#define null 0 /* using "null" because nil is predefined in Think C */

#ifndef EXPORT
#define EXPORT(returnType) returnType
#endif

#include "pharovm/semaphores/platformSemaphore.h"


#if !defined(IMAGE_DIALECT_NAME)
# if NewspeakVM
# define IMAGE_DIALECT_NAME "Newspeak"
Expand Down Expand Up @@ -57,28 +64,11 @@
If the platform requires special declaration modifiers, the EXPORT and
VM_EXPORT macros can be redefined.
*/
#define EXPORT(returnType) returnType
#define VM_EXPORT
#define VM_FUNCTION_EXPORT(returnType) returnType

/* Platform-dependent macros for handling object memory. */

/* Note: The grow/shrink macros assume that the object memory can be extended
continuously at its prior end. The garbage collector cannot deal with
'holes' in the object memory so the support code needs to reserve the
virtual maximum of pages that can be allocated beforehand. The amount of
'extra' memory should describe the amount of memory that can be allocated
from the OS (including swap space if the flag is set to true) and must not
exceed the prior reserved memory.
In other words: don't you dare to report more free space then you can
actually allocate.
The default implementation assumes a fixed size memory allocated at startup.
*/
#define sqAllocateMemory(minHeapSize, desiredHeapSize) malloc(desiredHeapSize)
#define sqGrowMemoryBy(oldLimit, delta) oldLimit
#define sqShrinkMemoryBy(oldLimit, delta) oldLimit
#define sqMemoryExtraBytesLeft(includingSwap) 0

#if SPURVM
/* Allocate a region of memory of al least sz bytes, at or above minAddr.
* If the attempt fails, answer null. If the attempt succeeds, answer the
Expand Down Expand Up @@ -255,6 +245,7 @@ sqInt ioSetWindowWidthHeight(sqInt w, sqInt h);
sqInt ioIsWindowObscured(void);

sqInt ioRelinquishProcessorForMicroseconds(sqInt microSeconds);

#if STACKVM || NewspeakVM
/* thread subsystem support for e.g. sqExternalSemaphores.c */
void ioInitThreads();
Expand Down
6 changes: 5 additions & 1 deletion extracted/vm/include/common/sqVirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef VM_PROXY_MINOR
/* Increment the following number if you add functions at the end */
# if SPURVM
# define VM_PROXY_MINOR 13
# define VM_PROXY_MINOR 15
# else
# define VM_PROXY_MINOR 12
# endif
Expand Down Expand Up @@ -373,6 +373,10 @@ typedef struct VirtualMachine {

sqInt (*isNonImmediate)(sqInt oop);

sqInt (*platformSemaphoreNew)(int initialValue);

sqInt (*scheduleInMainThread)(sqInt (*closure)());

} VirtualMachine;

#endif /* _SqueakVM_H */
2 changes: 1 addition & 1 deletion extracted/vm/src/common/sqNamedPrims.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ ioLoadSymbolOfLengthFromModule(sqInt functionNameIndex, sqInt functionNameLength
functionName[functionNameLength] = 0;
return moduleHandle
? ioFindExternalFunctionIn(functionName, moduleHandle)
: getModuleSymbol(NULL, functionName);
: getModuleSymbol(NULL, functionName);
}

/* ioLoadModuleOfLength
Expand Down
3 changes: 3 additions & 0 deletions extracted/vm/src/common/sqVirtualMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ struct VirtualMachine* sqGetInterpreterProxy(void)

VM->isNonImmediate = isNonImmediate;

VM->platformSemaphoreNew = platform_semaphore_new;
VM->scheduleInMainThread = mainThread_schedule;

return VM;
}

Expand Down
3 changes: 1 addition & 2 deletions extracted/vm/src/win/sqWin32SpurAlloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize)
SYSTEM_INFO sysInfo;

if (pageSize) {
sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"),
TEXT("sqAllocateMemory already called"));
logError("sqAllocateMemory have already been called");
exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion include/pharovm/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ EXPORT(void) installErrorHandlers();
#define logWarnFromErrno(msg) logMessageFromErrno(LOG_WARN, msg, __FILENAME__, __FUNCTION__, __LINE__);
#define logDebugFromErrno(msg) logMessageFromErrno(LOG_DEBUG, msg, __FILENAME__, __FUNCTION__, __LINE__);

void logMessageFromErrno(int level, const char* msg, const char* fileName, const char* functionName, int line);
EXPORT(void) logMessageFromErrno(int level, const char* msg, const char* fileName, const char* functionName, int line);

#include <stdio.h>

Expand Down
1 change: 1 addition & 0 deletions include/pharovm/pharo.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ void * loadModuleHandle(const char *fileName);
sqInt freeModuleHandle(void *module);
void *getModuleSymbol(void *module, const char *symbol);

EXPORT(sqInt) mainThread_schedule(sqInt (*closure)());

#endif //PHAROVM_PHARO_H
11 changes: 11 additions & 0 deletions include/pharovm/semaphores/pSemaphore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __PSEMAPHORE__
#define __PSEMAPHORE__

typedef struct __Semaphore {
void *handle;
int (*wait)(struct __Semaphore *semaphore);
int (*signal)(struct __Semaphore *semaphore);
void (*free)(struct __Semaphore *semaphore);
} Semaphore;

#endif // ifndef __PSEMAPHORE__
27 changes: 27 additions & 0 deletions include/pharovm/semaphores/platformSemaphore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __PLATFORM_SEMAPHORE__
#define __PLATFORM_SEMAPHORE__

#include "pSemaphore.h"
#include "pharovm/pharo.h"

#include <stdlib.h>

#ifndef __APPLE__
// I am a normal unix
#include <pthread.h>
#include <semaphore.h>
#include <errno.h>

typedef sem_t* PlatformSemaphore;
#define isValidSemaphore(aSemaphore) (aSemaphore != NULL)
#else
// I am OSX
#include <dispatch/dispatch.h>

typedef dispatch_semaphore_t PlatformSemaphore;
#define isValidSemaphore(aSemaphore) (1)
#endif // ifndef __APPLE__

EXPORT(Semaphore) *platform_semaphore_new(int initialValue);

#endif // ifndef __PLATFORM_SEMAPHORE__
54 changes: 47 additions & 7 deletions macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,28 @@ macro(get_full_platform_name VARNAME)
endif()
endmacro()

macro(get_full_platform_name_with_osx VARNAME)

macro(add_third_party_dependency NAME TARGETPATH)
if(SIZEOF_VOID_P EQUAL 8)
set(ARCH 64)
else()
set(ARCH 32)
endif()

get_platform_name(PLATNAME)
if(WIN)
set(${VARNAME} "win${ARCH}")
else()
if(OSX)
set(${VARNAME} "osx${ARCH}")
else()
set(${VARNAME} "linux${ARCH}")
endif()
endif()
endmacro()

message("Adding third-party libraries for ${PLATNAME}: ${NAME}")

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/third-party/${NAME}.zip"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build/third-party
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build/third-party wget --no-check-certificate "https://files.pharo.org/vm/pharo-spur64/${PLATNAME}/third-party/${NAME}.zip"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

macro(do_decompress_thirdparty NAME TARGETPATH)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/third-party/${NAME}.done"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${TARGETPATH}
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build/third-party unzip -o "${NAME}.zip" -d ${CMAKE_CURRENT_BINARY_DIR}/${TARGETPATH}
Expand All @@ -70,6 +80,36 @@ macro(add_third_party_dependency NAME TARGETPATH)
add_dependencies(${VM_EXECUTABLE_NAME} ${NAME})
endmacro()

macro(add_third_party_dependency NAME TARGETPATH)

get_platform_name(PLATNAME)

message("Adding third-party libraries for ${PLATNAME}: ${NAME}")

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/third-party/${NAME}.zip"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build/third-party
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build/third-party wget --no-check-certificate "https://files.pharo.org/vm/pharo-spur64/${PLATNAME}/third-party/${NAME}.zip"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

do_decompress_thirdparty(${NAME} ${TARGETPATH})
endmacro()

macro(add_third_party_dependency_from_jenkins LIBNAME TARGETPATH JOB BRANCH VERSION)
get_full_platform_name_with_osx(PLATNAME)

set(NAME ${LIBNAME}-${VERSION}-${PLATNAME})
set(URL "https://ci.inria.fr/pharo-ci-jenkins2/job/${JOB}/job/${BRANCH}/lastSuccessfulBuild/artifact/build/packages/${NAME}.zip")

message("Adding third-party libraries for ${PLATNAME} from Jenkins: ${NAME} (at ${URL})")

add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/third-party/${NAME}.zip"
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build/third-party
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build/third-party wget --no-check-certificate "${URL}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

do_decompress_thirdparty(${NAME} ${TARGETPATH})
endmacro()

macro(get_commit_hash VARNAME)
execute_process(
COMMAND git log -1 --format=%h
Expand Down
10 changes: 10 additions & 0 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,13 @@ static int loadPharoImage(const char* fileName)

return true;
}

/**
* This function is just an empty implementation that returns -1 as an error
*/
EXPORT(sqInt)
mainThread_schedule(sqInt (*closure)())
{
return -1;
}

22 changes: 13 additions & 9 deletions src/debug.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pharovm/pharo.h"
#include <stdarg.h>
#include <sys/time.h>

char * GetAttributeString(sqInt id);

Expand Down Expand Up @@ -28,7 +29,7 @@ void error(char *errorMessage){
abort();
}

static char* severityName[4] = {"ERROR", "WARN", "INFO", "DEBUG"};
static char* severityName[5] = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};

EXPORT(void) logAssert(const char* fileName, const char* functionName, int line, char* msg){
logMessage(LOG_WARN, fileName, functionName, line, msg);
Expand All @@ -38,16 +39,13 @@ void logMessageFromErrno(int level, const char* msg, const char* fileName, const
char buffer[1024+1];
int msgLength;

msgLength = strlen(msg);
strcpy(buffer, msg);

#ifdef WIN32
strerror_s(buffer + msgLength, 1024 - msgLength, errno);
strerror_s(buffer, 1024, errno);
#else
strerror_r(errno, buffer + msgLength, 1024 - msgLength);
strerror_r(errno, buffer, 1024);
#endif

logMessage(level, fileName, functionName, line, msg);
logMessage(level, fileName, functionName, line, "%s: %s", msg, buffer);
}

FILE* getStreamForLevel(int level){
Expand All @@ -73,11 +71,17 @@ EXPORT(void) logMessage(int level, const char* fileName, const char* functionNam
}

time_t now = time(NULL);
strftime(timestamp, 20, "%Y-%m-%d %H:%M:%S", localtime(&now));
struct tm* ltime = localtime(&now);

strftime(timestamp, 20, "%Y-%m-%d %H:%M:%S", ltime);

//Printing the header.
// Ex: [DEBUG] 2017-11-14 21:57:53,661 functionName (filename:line) - This is a debug log message.
fprintf(outputStream, "[%-5s] %s %s (%s:%d):", severityName[level - 1], timestamp, functionName, fileName, line);

struct timeval utcNow;
gettimeofday(&utcNow,0);

fprintf(outputStream, "[%-5s] %s.%03d %s (%s:%d):", severityName[level - 1], timestamp, utcNow.tv_usec / 1000 , functionName, fileName, line);

//Printint the message from the var_args.
va_list list;
Expand Down
Loading

0 comments on commit fecd981

Please sign in to comment.