Skip to content

Commit

Permalink
Merge branch 'ver/1.20.4' into ver/1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 8, 2024
2 parents b1a279d + 2e0009e commit b46a3d8
Show file tree
Hide file tree
Showing 48 changed files with 548 additions and 796 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "FlowSched"]
path = FlowSched
url = https://github.com/RelativityMC/FlowSched.git
1 change: 1 addition & 0 deletions FlowSched
Submodule FlowSched added at bf8183
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pipeline {
) {
sh 'git fetch --tags'
sh 'git reset --hard'
sh 'git submodule update --init --recursive --force'
sh './gradlew clean build'
}
}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021-2023 ishland
Copyright (c) 2021-2024 ishland

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ JDK 17+ is required to build and use C2ME
Run the following commands in the root directory:

```shell
git submodule update --init --recursive
./gradlew clean build
```

Expand Down
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "me.champeau.jmh" version "0.7.1"
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}

@SuppressWarnings('unused')
Expand Down Expand Up @@ -36,6 +37,8 @@ configure(allprojects) {

archivesBaseName = "${project.archives_base_name}-mc${project.minecraft_version}"

clean.dependsOn gradle.includedBuild('FlowSched').task(':clean')

configure (allprojects - project(":tests")) {
if (project != project(":") && project.parent != project(":")) return

Expand Down Expand Up @@ -118,6 +121,7 @@ configure (allprojects - project(":tests")) {
implementation "com.electronwill.night-config:toml:${night_config_version}"
implementation "org.threadly:threadly:${threadly_version}"
implementation "net.objecthunter:exp4j:${exp4j_version}"
implementation "com.ishland.flowsched:flowsched"

}
}
Expand Down Expand Up @@ -146,6 +150,7 @@ dependencies {
include implementation("com.electronwill.night-config:core:${night_config_version}")
include implementation("org.threadly:threadly:${threadly_version}")
include implementation("net.objecthunter:exp4j:${exp4j_version}")
// include implementation("com.ishland.flowsched:flowsched")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand Down Expand Up @@ -196,8 +201,9 @@ dependencies {
(subprojects - project(":tests")).forEach {
if (it.parent != project(":")) return

api project(path: ":${it.name}", configuration: "namedElements")
include project("${it.name}:")
def projectName = it.name
api project(path: ":${projectName}", configuration: "namedElements")
include project("${projectName}:")
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions c2me-base/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.github.johnrengelman.shadow'

configurations {
shadowInclude
}

dependencies {
shadowInclude("com.ishland.flowsched:flowsched") {
transitive false
}
}

shadowJar {
archiveClassifier = "all-dev"
configurations = [ project.configurations.shadowInclude ]
}

remapJar {
input = shadowJar.archiveFile
archiveFileName = shadowJar.archiveFileName.get().replaceAll("-dev\\.jar\$", ".jar")
addNestedDependencies = true
dependsOn shadowJar
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ModuleEntryPoint {
(cpus / 1.2 - 2)
),
if( is_j9vm,
( ( mem_gb - (if(is_client, 0.6, 0.2)) ) / 0.5 ),
( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 1.2 )
( ( mem_gb - (if(is_client, 0.6, 0.2)) ) / 0.4 ),
( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 0.6 )
)
) - if(is_client, 2, 0)
)
Expand Down Expand Up @@ -88,19 +88,22 @@ public double apply(double... args) {
public static final long globalExecutorParallelism;

static {
final int defaultEval = tryEvaluateExpression(DEFAULT_EXPRESSION);
int value;
try {
value = tryEvaluateExpression(defaultGlobalExecutorParallelismExpression);
} catch (Throwable t) {
ConfigSystem.LOGGER.error("Failed to evaluate defaultGlobalExecutorParallelismExpression, falling back to default value", t);
value = tryEvaluateExpression(DEFAULT_EXPRESSION);
value = defaultEval;
}

defaultParallelism = value;
globalExecutorParallelism = new ConfigSystem.ConfigAccessor()
.key("globalExecutorParallelism")
.comment("Configures the parallelism of global executor")
.getLong(value, value, ConfigSystem.LongChecks.THREAD_COUNT);

ConfigSystem.LOGGER.info("Global Executor Parallelism: {} configured, {} evaluated, {} default evaluated", globalExecutorParallelism, defaultParallelism, defaultEval);
}

// public static int getDefaultGlobalExecutorParallelism() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,23 @@

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.ishland.c2me.base.ModuleEntryPoint;
import com.ishland.c2me.base.common.util.C2MENormalWorkerThreadFactory;
import com.ishland.flowsched.executor.ExecutorManager;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class GlobalExecutors {

// private static final C2MEForkJoinWorkerThreadFactory factory = new C2MEForkJoinWorkerThreadFactory("c2me", "C2ME worker #%d", Thread.NORM_PRIORITY - 1);
private static final C2MENormalWorkerThreadFactory factory = new C2MENormalWorkerThreadFactory("c2me", "C2ME worker #%d", Thread.NORM_PRIORITY - 1);
public static final int GLOBAL_EXECUTOR_PARALLELISM = (int) ModuleEntryPoint.globalExecutorParallelism;
// public static final ForkJoinPool executor = new ForkJoinPool(
// GLOBAL_EXECUTOR_PARALLELISM,
// factory,
// null,
// true
// );
public static final ExecutorService executor = Executors.newFixedThreadPool(GLOBAL_EXECUTOR_PARALLELISM, factory);
public static final Executor invokingExecutor = r -> {
if (Thread.currentThread().getThreadGroup() == factory.getThreadGroup()) {
r.run();
} else {
executor.execute(r);
}
};
private static final AtomicInteger prioritizedSchedulerCounter = new AtomicInteger(0);
public static final ExecutorManager prioritizedScheduler = new ExecutorManager(GlobalExecutors.GLOBAL_EXECUTOR_PARALLELISM, thread -> {
thread.setDaemon(true);
thread.setName("c2me-prioritized-%d".formatted(prioritizedSchedulerCounter.getAndIncrement()));
});

public static final ExecutorService asyncScheduler = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public long getLong(long def, long incompatibleDef, LongChecks... checks) {
if (this.incompatibilityDetected) return incompatibleDef;
long configLong = isDefaultValue ? def : CONFIG.getLong(this.key);
if (checkConfig(configLong, checks)) {
if (!isDefaultValue) {
logChanged(def, configLong);
}
return configLong;
} else {
CONFIG.remove(this.key);
Expand Down Expand Up @@ -183,7 +186,11 @@ public boolean getBoolean(boolean def, boolean incompatibleDef) {
}
generateDefaultEntry(def, incompatibleDef);

return this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.get(this.key));
final boolean b = this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.get(this.key));
if (!isDefaultValue) {
logChanged(def, b);
}
return b;
}

public <T extends Enum<T>> T getEnum(Class<T> enumClass, T def, T incompatibleDef) {
Expand All @@ -209,7 +216,11 @@ public <T extends Enum<T>> T getEnum(Class<T> enumClass, T def, T incompatibleDe
}
generateDefaultEntry(def, incompatibleDef);

return this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.getEnum(this.key, enumClass));
final T t = this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.getEnum(this.key, enumClass));
if (!isDefaultValue) {
logChanged(def, t);
}
return t;
}

public String getString(String def, String incompatibleDef) {
Expand All @@ -231,7 +242,11 @@ public String getString(String def, String incompatibleDef) {
}
generateDefaultEntry(def, incompatibleDef);

return this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.get(this.key));
final String s = this.incompatibilityDetected ? incompatibleDef : (isDefaultValue ? def : CONFIG.get(this.key));
if (!isDefaultValue) {
logChanged(def, s);
}
return s;
}

private void findModDefinedIncompatibility() {
Expand Down Expand Up @@ -279,6 +294,10 @@ private void generateDefaultEntry(Object def, Object incompatibleDef) {
}
}

private void logChanged(Object def, Object config) {
LOGGER.info("Config {} changed from {} to {}", this.key, String.valueOf(def), String.valueOf(config));
}

private void markVisited() {
visitedConfig.add(this.key);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.ishland.c2me.base.common.scheduler;

import com.ishland.flowsched.executor.Task;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;

import java.util.Objects;

public abstract class AbstractPosAwarePrioritizedTask implements Task {

protected final ReferenceArrayList<Runnable> postExec = new ReferenceArrayList<>(4);
private final long pos;
private int priority = Integer.MAX_VALUE;

public AbstractPosAwarePrioritizedTask(long pos) {
this.pos = pos;
}

@Override
public int priority() {
return this.priority;
}

public void setPriority(int priority) {
this.priority = priority;
}

public long getPos() {
return this.pos;
}

public void addPostExec(Runnable runnable) {
synchronized (this.postExec) {
postExec.add(Objects.requireNonNull(runnable));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ishland.c2me.base.common.scheduler;

import com.ishland.flowsched.executor.LockToken;

public record LockTokenImpl(int ownerTag, long pos) implements LockToken {
}

This file was deleted.

Loading

0 comments on commit b46a3d8

Please sign in to comment.