Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove no longer needed garbage collector meddling. #971

Merged
merged 5 commits into from
Dec 1, 2024
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
18 changes: 12 additions & 6 deletions src/freenet/config/SubConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,47 +172,53 @@ public int getInt(String optionName) {
synchronized(this) {
o = (IntOption) map.get(optionName);
}
return o.getValue();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? -1 : o.getValue();
Bombe marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines 173 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace the ternaries with the more descriptive Map.getOrDefault?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried: not without increasing the complexity, because map returns an option which does not have a simple constructor from just a value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. I kind of forgot about the mess the constructor of Option is 😞

Spoiler:

Option(SubConfig config, String name, ConfigCallback<T> cb, int sortOrder, boolean expert, boolean forceWrite,
	String shortDesc, String longDesc, DataType dataType) {

Well then let's stick with the ternaries!

}

public long getLong(String optionName) {
LongOption o;
synchronized(this) {
o = (LongOption) map.get(optionName);
}
return o.getValue();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? -1L : o.getValue();
}

public boolean getBoolean(String optionName) {
BooleanOption o;
synchronized(this) {
o = (BooleanOption) map.get(optionName);
}
return o.getValue();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? false : o.getValue();
}

public String getString(String optionName) {
StringOption o;
synchronized(this) {
o = (StringOption) map.get(optionName);
}
return o.getValue().trim();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? "" : o.getValue().trim();
}

public String[] getStringArr(String optionName) {
StringArrOption o;
synchronized(this) {
o = (StringArrOption) map.get(optionName);
}
return o.getValue();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? new String[]{} : o.getValue();
}

public short getShort(String optionName) {
ShortOption o;
synchronized(this) {
o = (ShortOption) map.get(optionName);
}
return o.getValue();
// return fallback value for ignored options (null). This avoids breaking plugins which try to get ignored options.
return o == null ? -1 : o.getValue();
}

public Option<?> removeOption(String optionName) {
Expand Down
108 changes: 0 additions & 108 deletions src/freenet/node/MemoryChecker.java

This file was deleted.

43 changes: 2 additions & 41 deletions src/freenet/node/NodeStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ final int[] getCounts(final int[] total) {
private volatile long maxPingTime;

final Node node;
private MemoryChecker myMemoryChecker;
public final PeerManager peers;

final RandomSource hardRandom;
Expand Down Expand Up @@ -284,10 +283,6 @@ public void shouldUpdate(){
final StringCounter preemptiveRejectReasons;
final StringCounter localPreemptiveRejectReasons;

// Enable this if you run into hard to debug OOMs.
// Disabled to prevent long pauses every 30 seconds.
private int aggressiveGCModificator = -1 /*250*/;

// Peers stats
/** Next time to update PeerManagerUserAlert stats */
private long nextPeerManagerUserAlertStatsUpdateTime = -1;
Expand Down Expand Up @@ -407,43 +402,9 @@ public void set(Integer val) throws InvalidConfigValueException {
threadLimit = statsConfig.getInt("threadLimit");

// Yes it could be in seconds insteed of multiples of 0.12, but we don't want people to play with it :)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment can also be removed. 🙂

statsConfig.register("aggressiveGC", aggressiveGCModificator, sortOrder++, true, false, "NodeStat.aggressiveGC", "NodeStat.aggressiveGCLong",
new IntCallback() {
@Override
public Integer get() {
return aggressiveGCModificator;
}
@Override
public void set(Integer val) throws InvalidConfigValueException {
if (get().equals(val))
return;
Logger.normal(this, "Changing aggressiveGCModificator to "+val);
aggressiveGCModificator = val;
}
},false);
aggressiveGCModificator = statsConfig.getInt("aggressiveGC");

myMemoryChecker = new MemoryChecker(node.getTicker(), aggressiveGCModificator);
statsConfig.register("memoryChecker", true, sortOrder++, true, false, "NodeStat.memCheck", "NodeStat.memCheckLong",
new BooleanCallback(){
@Override
public Boolean get() {
return myMemoryChecker.isRunning();
}

@Override
public void set(Boolean val) throws InvalidConfigValueException {
if (get().equals(val))
return;
statsConfig.registerIgnoredOption("aggressiveGC");

if(val)
myMemoryChecker.start();
else
myMemoryChecker.terminate();
}
});
if(statsConfig.getBoolean("memoryChecker"))
myMemoryChecker.start();
statsConfig.registerIgnoredOption("memoryChecker");

statsConfig.register("ignoreLocalVsRemoteBandwidthLiability", false, sortOrder++, true, false, "NodeStat.ignoreLocalVsRemoteBandwidthLiability", "NodeStat.ignoreLocalVsRemoteBandwidthLiabilityLong", new BooleanCallback() {

Expand Down