Skip to content

Commit

Permalink
Merge bug/REL1_6_STABLE/issue471 and port/REL1_6_STABLE/FreeBSD2023
Browse files Browse the repository at this point in the history
Merges pull requests #476 and #478.
  • Loading branch information
jcflack committed Mar 25, 2024
3 parents c7eea1e + 9a1f669 + 99a1daa commit 02b2421
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
41 changes: 41 additions & 0 deletions pljava-so/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,47 @@
}
},
{
name : "FreeBSD",
object_extension : ".o",
probe: function(os_name) {
return os_name.toLowerCase().contains("freebsd");
},
compile : function(cc, files, output_dir, includes, defines, flags) {
includes.add(java_include.resolve("freebsd").toString());
defines.put("FreeBSD", null);
flags.add("-c");
if(isDebugEnabled)
flags.add("-g");
var compileProcess = utils.processBuilder(function(l) {
l.add(cc);
l.addAll(pgxs.formatDefines(defines));
l.addAll(pgxs.formatIncludes(includes));
l.addAll(flags);
l.addAll(files);
});
compileProcess.directory(output_dir.toFile());
return runCommand(compileProcess);
},
link : function(cc, flags, files, target_path) {
if(isDebugEnabled)
flags.add("-g");
flags.add("-shared-libgcc");
var linkingProcess = utils.processBuilder(function(l) {
l.add(cc);
l.addAll(flags);
l.addAll(of("-shared", "-o", "lib" + library_name + ".so"));
l.addAll(files);
});
linkingProcess.directory(target_path.toFile());
return runCommand(linkingProcess);
}
},
{
name : "Mac OS X",
Expand Down
36 changes: 20 additions & 16 deletions pljava/src/main/java/org/postgresql/pljava/internal/Portal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2019 Tada AB and other contributors, as listed below.
* Copyright (c) 2004-2023 Tada AB and other contributors, as listed below.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the The BSD 3-Clause License
Expand All @@ -25,28 +25,29 @@
*/
public class Portal
{
/*
* Hold a reference to the Java ExecutionPlan object as long as we might be
* using it, just to make sure Java unreachability doesn't cause it to
* mop up its native plan state while the portal might still be using it.
*/
private ExecutionPlan m_plan;

private final State m_state;

Portal(DualState.Key cookie, long ro, long pointer, ExecutionPlan plan)
{
m_state = new State(cookie, this, ro, pointer);
m_plan = plan;
m_state = new State(cookie, this, ro, pointer, plan);
}

private static class State
extends DualState.SingleSPIcursorClose<Portal>
{
/*
* Hold a reference to the Java ExecutionPlan object as long as we might
* be using it, just to make sure Java unreachability doesn't cause it
* to mop up its native plan state while the portal might still want it.
*/
private ExecutionPlan m_plan;

private State(
DualState.Key cookie, Portal referent, long ro, long portal)
DualState.Key cookie, Portal referent, long ro, long portal,
ExecutionPlan plan)
{
super(cookie, referent, ro, portal);
m_plan = plan;
}

/**
Expand Down Expand Up @@ -76,6 +77,13 @@ private long getPortalPtr() throws SQLException
unpin();
}
}

@Override
protected void javaStateReleased(boolean nativeStateLive)
{
super.javaStateReleased(nativeStateLive);
m_plan = null;
}
}

/**
Expand All @@ -84,11 +92,7 @@ private long getPortalPtr() throws SQLException
*/
public void close()
{
doInPG(() ->
{
m_state.releaseFromJava();
m_plan = null;
});
m_state.releaseFromJava();
}

/**
Expand Down
22 changes: 3 additions & 19 deletions src/site/markdown/build/freebsd.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
# Building on FreeBSD

At one time, [FreeBSD][]'s threading library would malfunction if it was
dynamically loaded after the start of a program that did not use threads
itself. That was a problem for PL/Java on FreeBSD, because PostgreSQL
itself does not use threads, but Java does. The only known workaround was
to build PostgreSQL itself from source, with the thread library included
in linking.

The same problem was [reported to affect other PostgreSQL extensions][rep]
such as `plv8` and `imcs` also.

The [manual page for FreeBSD's libthr][manthr] was edited
[in February 2015][thrdif] to remove the statement of that limitation,
and the updated manual page appears first in [FreeBSD 10.2][rel102],
so in FreeBSD 10.2 or later, PL/Java (and other affected extensions)
may work without the need to build PostgreSQL from source.
Building on [FreeBSD][] should proceed just as it does on Linux,
as of late 2023, according to Achilleos Mantzios, who provided the patch
adding the necessary build rules.

[FreeBSD]: https://www.freebsd.org/
[rep]: https://lists.freebsd.org/pipermail/freebsd-hackers/2014-April/044961.html
[manthr]: https://www.freebsd.org/cgi/man.cgi?query=libthr&amp;apropos=0&amp;sektion=3&amp;manpath=FreeBSD+10.2-RELEASE&amp;arch=default&amp;format=html
[thrdif]: https://svnweb.freebsd.org/base/head/lib/libthr/libthr.3?r1=272153&amp;r2=278627
[rel102]: https://www.freebsd.org/releases/10.2R/announce.html

0 comments on commit 02b2421

Please sign in to comment.