Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/Kernel/ActiveProcess.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ ActiveProcess >> beInactive [
self changeClassTo: SuspendedProcess
]

{ #category : #testing }
ActiveProcess >> isActive [
^true
]

{ #category : #converting }
ActiveProcess >> canReturnTo: homeFrame [

Expand Down
4 changes: 2 additions & 2 deletions modules/Kernel/Context.st
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Context >> code: anExecutableCode method: aCompiledMethod [

{ #category : #services }
Context >> copyAllTo: aProcessStack [
| start offset |
start := parent copyAllTo: aProcessStack.
| start |
start := caller copyAllTo: aProcessStack.
^self copyTo: aProcessStack at: start
]

Expand Down
13 changes: 9 additions & 4 deletions modules/Kernel/HostSystem.st
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ HostSystem >> prependSearchPath: aString type: aSymbol [

{ #category : #loading }
HostSystem >> primitiveLoad: aSymbol [
| error |
<primitive: HostLoadModule>
^Error signal: error
]

{ #category : #loading }
HostSystem >> primitiveLoadModuleFromPath: aString [
| error |
<primitive: HostLoadModuleFromPath>
^Error signal: error
]

{ #category : #services }
Expand All @@ -177,16 +181,15 @@ HostSystem >> setupDefaultSearchPaths [
platform-native PATH separator) supplies extra source directories. We also
walk a few levels up from the current directory so the runtime works both
from the project root and from a build subdirectory."
| env home cwd prefixes |
| env home prefixes |
env := self getEnv: 'EGG_MODULES_PATH'.
env ifNotNil: [
(env substringsSplitBy: self pathSeparator) do: [:p |
self addSearchPath: p type: #tonel.
self addSearchPath: p type: #ems]].
cwd := self currentDirectory.
prefixes := #('' '../' '../../' '../../../' '../../../../').
prefixes do: [:p | | base |
base := cwd , '/' , p , 'modules'.
base := p , 'modules'.
(self pathExists: base) ifTrue: [
self addSearchPath: base type: #tonel.
self addSearchPath: base type: #ems]].
Expand All @@ -200,7 +203,9 @@ HostSystem >> setupDefaultSearchPaths [

{ #category : #private }
HostSystem >> suspended: aProcess because: anException [
<primitive: HostSuspendedBecause>
self
logError: 'Error: ' , anException description;
exit: 1
]

{ #category : #services }
Expand Down
1 change: 0 additions & 1 deletion modules/Kernel/KernelModule.st
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ KernelModule >> suspendOnUnhandledExceptions [
KernelModule >> suspendBecause: anException [
| active process |
active := Processor activeProcess.
"active snapshot ifNil: [^self]."
process := Process sending: #suspended:because: to: host with: {active. anException}.
process takeControl
]
Expand Down
7 changes: 6 additions & 1 deletion modules/Kernel/Process.st
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ Process >> findHandlerFor: anException [

{ #category : #private }
Process >> initializeStack [
nativeStack := ProcessStack on: self
nativeStack := ProcessVMStack on: self
]

{ #category : #testing }
Process >> isActive [
^false
]

{ #category : #private }
Expand Down
17 changes: 14 additions & 3 deletions modules/Kernel/ProcessStack.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Class {
#instVars : [
'process',
'sp',
'bp'
'bp',
'env'
],
#category : #Kernel
}
Expand All @@ -35,8 +36,18 @@ ProcessStack >> contextSwitchTo: next [
{ #category : #services }
ProcessStack >> fillFrom: aContext [
#CRITICAL.
sp := (aContext copyAllTo: self).
self at: sp put: aContext lastEnvironment
sp := aContext copyAllTo: self.
env := aContext lastEnvironment
]

{ #category : #accessing }
ProcessStack >> env [
^env
]

{ #category : #accessing }
ProcessStack >> env: anObject [
env := anObject
]

{ #category : #accessing }
Expand Down
28 changes: 22 additions & 6 deletions modules/Kernel/ProcessVMStack.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
Class {
#name : #ProcessVMStack,
#superclass : #ProcessStack,
#instVars : [
'buffer',
'bufferSize'
],
#category : #Kernel
}

{ #category : 'instance creation' }
ProcessVMStack class >> on: aProcess [
^self new process: aProcess
]

{ #category : 'Primitives' }
ProcessVMStack >> at: anInteger [
<primitive: ProcessVMStackAt>
Expand All @@ -20,8 +29,13 @@ ProcessVMStack >> at: anInteger put: anObject [
]

{ #category : 'Primitives' }
ProcessVMStack >> basicInitialize [
<primitive: ProcessVMStackInitialize>
ProcessVMStack >> initializeWithNewBuffer [
<primitive: ProcessVMStackInitializeWithNewBuffer>
]

{ #category : 'Primitives' }
ProcessVMStack >> initializeWithActiveBuffer [
<primitive: ProcessVMStackInitializeWithActiveBuffer>
]

{ #category : #primitives }
Expand Down Expand Up @@ -49,10 +63,12 @@ ProcessVMStack >> contextSwitchTo: aProcessStack [
<primitive: ProcessVMStackContextSwitchTo>
]

{ #category : 'initializing' }
ProcessVMStack >> initialize [
super initialize.
self basicInitialize
{ #category : 'accessing' }
ProcessVMStack >> process: aProcess [
super process: aProcess.
aProcess isActive
ifTrue: [self initializeWithActiveBuffer]
ifFalse: [self initializeWithNewBuffer]
]

{ #category : 'Primitives' }
Expand Down
5 changes: 5 additions & 0 deletions modules/Kernel/String.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ String class >> fromUTF8: aByteArray [
ifFalse: [UTF8 current decode: aByteArray]
]

{ #category : #'instance creation' }
String class >> new [
^self new: 0
]

{ #category : #'instance creation' }
String class >> new: anInteger [
^self primitiveNewBytes: anInteger + 1
Expand Down
56 changes: 23 additions & 33 deletions runtime/cpp/Allocator/GarbageCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,23 @@ void GarbageCollector::nativeFramesStartingAt_bp_do_(uintptr_t **stack, uintptr_
}
}

void GarbageCollector::scanFirstStackChunk_(HeapObject *aProcessVMStack) {
/**
* Scanning needs to fetch a chain of stack (frame) pointers. The head
* of the chain is either of two cases:
* - The active process.
* In that case, the top of the stack is a common frame (probably a call
* to a primitive). No special action needs to be done.
* - A sleeping (native) process.
* In that case, the top of the stack is that process' env, followed
* by a retaddr. The GC has to scan that addr and then continue normally.
* (TODO: make env an instvar of the ProcessVMStack)
*/
//if (aProcessVMStack != runtime->_activeProcessStack)
// this->scanTopSlot_(aProcessVMStack);

auto firstSP = _runtime->processVMStackSP_(aProcessVMStack) + 2;
auto firstBP = _runtime->processVMStackBP_(aProcessVMStack);
auto stack = (uintptr_t**)nullptr; //_runtime->processVMStackContext_(aProcessVMStack)->stack();
this->nativeFramesStartingAt_bp_do_(stack, firstSP, firstBP,
void GarbageCollector::scanStack_sp_bp_(uintptr_t **stack, uintptr_t sp, uintptr_t bp) {
this->nativeFramesStartingAt_bp_do_(stack, sp, bp,
[this](uintptr_t *frame, uintptr_t size) {
this->scanNativeStackFrame_sized_(frame, size);
});
}

void GarbageCollector::scanSuspendedProcessStack_(HeapObject *aProcessVMStack) {
// A suspended process' topmost frame was laid out by ProcessStack>>fillFrom:.
// `sp` ivar is the slot just below the saved-bp slot of that topmost frame
// Start the frame walk at sp+1 (saved-bp slot) up to bp.
auto firstSP = _runtime->processStackSP_(aProcessVMStack) + 1;
auto firstBP = _runtime->processStackBP_(aProcessVMStack);
auto stack = (uintptr_t**)_runtime->processVMStackBuffer_(aProcessVMStack);
this->scanStack_sp_bp_(stack, firstSP, firstBP);
}

void GarbageCollector::scanPointer_(Object** pointer)
{
this->scanRoot_(pointer);
Expand All @@ -230,27 +223,24 @@ void GarbageCollector::scanCurrentContext() {
this->scanPointer_((Object**)&context->_regE);
this->scanPointer_((Object**)&context->_regM);


auto firstSP = context->stackPointer();
auto firstBP = context->framePointer();
auto stack = (uintptr_t**)context->stack();
this->nativeFramesStartingAt_bp_do_(stack, firstSP, firstBP,
[this](uintptr_t *frame, uintptr_t size) {
this->scanNativeStackFrame_sized_(frame, size);
});
this->scanStack_sp_bp_(
(uintptr_t**)context->stack(),
context->stackPointer(),
context->framePointer());
}

void GarbageCollector::scanStack_(HeapObject *aProcessVMStack)
{
//auto context = _runtime->processVMStackContext_(aProcessVMStack);

// skip this stack if it corresponds to active process, which has already been scanned
//if (context == _runtime->_evaluator->context())
// Skip this stack if it corresponds to the active process: its buffer is
// the one bound to the live evaluator context, which scanCurrentContext
// has already walked using the live SP/BP/regs.
auto buffer = _runtime->processVMStackBuffer_(aProcessVMStack);
if (buffer == _runtime->_evaluator->context()->stack())
return;

auto process = _runtime->processVMStackProcess_(aProcessVMStack);
auto process = _runtime->processStackProcess_(aProcessVMStack);
if (_runtime->processStackIsValid_(process))
this->scanFirstStackChunk_(aProcessVMStack);
this->scanSuspendedProcessStack_(aProcessVMStack);

/* unimplemented GC in callbacks
this->stackFramesBeneathCallbackIn_Do_(aProcessVMStack,
Expand Down
3 changes: 2 additions & 1 deletion runtime/cpp/Allocator/GarbageCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class GarbageCollector {
void scanSpecialSlots_(HeapObject *special);

void nativeFramesStartingAt_bp_do_(uintptr_t **stack, uintptr_t sp, uintptr_t bp, std::function<void(uintptr_t*, uintptr_t)> block);
void scanFirstStackChunk_(HeapObject * aProcessVMStack);
void scanStack_sp_bp_(uintptr_t **stack, uintptr_t sp, uintptr_t bp);
void scanSuspendedProcessStack_(HeapObject * aProcessVMStack);
void scanPointer_(Object **pointer);
void scanCurrentContext();
void scanStack_(HeapObject *aProcessVMStack);
Expand Down
4 changes: 2 additions & 2 deletions runtime/cpp/Bootstrap/Bootstrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Bootstrapper::loadKernelSpecs() {
if (className == "package") continue;

std::string source = readSourceFile_(className);
ClassSpec* spec = reader.parseFile(source);
ClassSpec* spec = reader.parseFile(source, entry.path().string());
_moduleSpec.addClass(spec);
}
}
Expand All @@ -107,7 +107,7 @@ void Bootstrapper::loadKernelSpecs() {
if (!file.is_open()) continue;
std::string source((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());

ClassSpec* extensionSpec = reader.parseFile(source);
ClassSpec* extensionSpec = reader.parseFile(source, entry.path().string());
ClassSpec* existingSpec = _moduleSpec.resolveClass(className);
if (!existingSpec) {
std::cerr << " Warning: VM extension for unknown class " << className << std::endl;
Expand Down
37 changes: 28 additions & 9 deletions runtime/cpp/Bootstrap/SourceModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdexcept>

namespace Egg {

Expand Down Expand Up @@ -59,7 +61,7 @@ HeapObject* SourceModuleLoader::loadModuleFromSource(const std::string& modulePa
std::string source((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());

ClassSpec* spec = reader.parseFile(source);
ClassSpec* spec = reader.parseFile(source, entry.path().string());
_moduleSpec.addClass(spec);
if (spec->isExtension()) {
extensionNames.push_back(spec->name());
Expand Down Expand Up @@ -302,17 +304,34 @@ Object* SourceModuleLoader::createNewClassFrom_(ClassSpec* spec, Object* module)
void SourceModuleLoader::createMethodsOf_(Object* cls, ClassSpec* spec) {
GCedRef clsRef(cls);

// Instance methods
for (const auto& method : spec->methods()) {
createNewMethod_(method.source(), clsRef.get(), method.category());
}
auto runMethod = [&](const MethodSpec& method, Object* receiver, const std::string& side) {
try {
createNewMethod_(method.source(), receiver, method.category());
} catch (const std::exception& e) {
rethrowWithContext_(e, spec->name(), side, method.source());
}
};

for (const auto& method : spec->methods())
runMethod(method, clsRef.get(), "");

// Class methods
auto metaclass = _runtime->sendLocal_to_("class", clsRef.get());
GCedRef metaRef(metaclass);
for (const auto& method : spec->metaclass()->methods()) {
createNewMethod_(method.source(), metaRef.get(), method.category());
}
for (const auto& method : spec->metaclass()->methods())
runMethod(method, metaRef.get(), " class");
}

[[noreturn]] void SourceModuleLoader::rethrowWithContext_(const std::exception& e,
const Egg::string& className,
const std::string& side,
const Egg::string& source) {
size_t nl = source.find(U'\n');
Egg::string sig = nl == Egg::string::npos ? source : source.substr(0, nl);
std::stringstream ss;
ss << e.what()
<< "\n while compiling " << className.toUtf8() << side
<< " >> " << sig.toUtf8();
throw std::runtime_error(ss.str());
}

void SourceModuleLoader::createNewMethod_(const Egg::string& source, Object* species, const Egg::string& category) {
Expand Down
4 changes: 4 additions & 0 deletions runtime/cpp/Bootstrap/SourceModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SourceModuleLoader {
Object* createNewClassFrom_(ClassSpec* spec, Object* module);
void createMethodsOf_(Object* cls, ClassSpec* spec);
void createNewMethod_(const Egg::string& source, Object* species, const Egg::string& category = Egg::string(""));
[[noreturn]] static void rethrowWithContext_(const std::exception& e,
const Egg::string& className,
const std::string& side,
const Egg::string& source);
Object* createExtensionMethod_(const Egg::string& source, Object* species);

// Literal transfer helpers
Expand Down
Loading
Loading