JBoss Native SVN: r1100 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 09:52:51 -0400 (Thu, 11 Oct 2007)
New Revision: 1100
Modified:
trunk/sight/native/os/solaris/service.c
Log:
Modified: trunk/sight/native/os/solaris/service.c
===================================================================
--- trunk/sight/native/os/solaris/service.c 2007-10-11 13:41:32 UTC (rev 1099)
+++ trunk/sight/native/os/solaris/service.c 2007-10-11 13:52:51 UTC (rev 1100)
@@ -1,253 +1,253 @@
-/*
- * SIGHT - System information gathering hybrid tool
- *
- * Copyright(c) 2007 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Mladen Turk
- *
- */
-
-/**
- * Service implementation
- *
- */
-
-#include "sight.h"
-#include "sight_local.h"
-#include "sight_types.h"
-#include "sight_private.h"
-
-#include <sys/stat.h>
-
-J_DECLARE_CLAZZ = {
- NULL,
- NULL,
- SIGHT_CLASS_PATH "Service"
-};
-
-J_DECLARE_F_ID(0000) = {
- NULL,
- "Name",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0001) = {
- NULL,
- "BinaryPathName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0002) = {
- NULL,
- "Dependencies",
- "[Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0003) = {
- NULL,
- "ServiceStartName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0004) = {
- NULL,
- "DisplayName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0005) = {
- NULL,
- "Description",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0006) = {
- NULL,
- "LoadOrderGroup",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0007) = {
- NULL,
- "ExitCode",
- "I"
-};
-
-J_DECLARE_F_ID(0008) = {
- NULL,
- "ServiceSpecificExitCode",
- "I"
-};
-
-J_DECLARE_F_ID(0009) = {
- NULL,
- "ProcessId",
- "I"
-};
-
-J_DECLARE_M_ID(0000) = {
- NULL,
- "setState",
- "(I)V"
-};
-
-SIGHT_CLASS_LDEF(Service)
-{
- if (sight_load_class(_E, &_clazzn))
- return 1;
- J_LOAD_IFIELD(0000);
- J_LOAD_IFIELD(0001);
- J_LOAD_IFIELD(0002);
- J_LOAD_IFIELD(0003);
- J_LOAD_IFIELD(0004);
- J_LOAD_IFIELD(0005);
- J_LOAD_IFIELD(0006);
- J_LOAD_IFIELD(0007);
- J_LOAD_IFIELD(0008);
- J_LOAD_IFIELD(0009);
- J_LOAD_METHOD(0000);
-
- return 0;
-}
-
-SIGHT_CLASS_UDEF(Service)
-{
- sight_unload_class(_E, &_clazzn);
-}
-
-
-SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jlong scm,
- jstring name,
- jint access)
-{
- sight_object_t *no = J2P(instance, sight_object_t *);
- sight_object_t *ns = J2P(scm, sight_object_t *);
- scm_instance_t *si;
- SIGHT_ALLOC_CSTRING(name);
- int rc = 0;
- int state = SIGHT_SS_DISABLED;
- char rlpath[PATH_MAX];
- DIR *rd = NULL;
-
-
- UNREFERENCED_O;
- UNREFERENCED(access);
-
- if (!no || !no->pool) {
- SIGHT_FREE_CSTRING(name);
- return APR_EINVAL;
- }
- if (!ns || !ns->native) {
- SIGHT_FREE_CSTRING(name);
- return APR_EINVAL;
- }
- si = (scm_instance_t *)ns->native;
- sprintf(rlpath, si->rlpath, si->what);
-
-sretry:
- if ((rd = opendir(rlpath))) {
- struct dirent *sent, sbuf;
- while (!readdir_r(rd, &sbuf, &sent)) {
- char sname[PATH_MAX];
- char smatch[PATH_MAX];
- struct stat sb;
- if (!sent)
- break;
- strcpy(sname, rlpath);
- strcat(sname, sent->d_name);
- strcpy(smatch, "*/S??");
- strcat(smatch, J2S(name));
- /* Match the SnnName */
- if (!sight_wmatch(sname, smatch)) {
- SET_IFIELD_S(0001, thiz, sname);
- SET_IFIELD_S(0004, thiz, sent->d_name);
-
- /* TODO: Launch script with status param
- * to figure out the state.
- */
- state = SIGHT_SS_UNKNOWN;
- break;
- }
- }
- closedir(rd);
- CALL_METHOD1(0000, thiz, state);
- }
- if (state == SIGHT_SS_DISABLED &&
- strcmp(rlpath, "/etc/rcS.d/")) {
- strcpy(rlpath, "/etc/rcS.d/");
- goto sretry;
- }
- SIGHT_FREE_CSTRING(name);
- return APR_FROM_OS_ERROR(rc);
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, ctrl0)(SIGHT_STDARGS,
- jlong instance,
- jint cmd)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(instance);
- UNREFERENCED(cmd);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, stats0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, wait0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jlong timeout,
- jint state)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(timeout);
- UNREFERENCED(state);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, wait1)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jobject progress,
- jlong timeout,
- jint state)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(progress);
- UNREFERENCED(timeout);
- UNREFERENCED(state);
- return APR_ENOTIMPL;
-}
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ *
+ */
+
+/**
+ * Service implementation
+ *
+ */
+
+#include "sight.h"
+#include "sight_local.h"
+#include "sight_types.h"
+#include "sight_private.h"
+
+#include <sys/stat.h>
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ SIGHT_CLASS_PATH "Service"
+};
+
+J_DECLARE_F_ID(0000) = {
+ NULL,
+ "Name",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0001) = {
+ NULL,
+ "BinaryPathName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0002) = {
+ NULL,
+ "Dependencies",
+ "[Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0003) = {
+ NULL,
+ "ServiceStartName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0004) = {
+ NULL,
+ "DisplayName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0005) = {
+ NULL,
+ "Description",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0006) = {
+ NULL,
+ "LoadOrderGroup",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0007) = {
+ NULL,
+ "ExitCode",
+ "I"
+};
+
+J_DECLARE_F_ID(0008) = {
+ NULL,
+ "ServiceSpecificExitCode",
+ "I"
+};
+
+J_DECLARE_F_ID(0009) = {
+ NULL,
+ "ProcessId",
+ "I"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "setState",
+ "(I)V"
+};
+
+SIGHT_CLASS_LDEF(Service)
+{
+ if (sight_load_class(_E, &_clazzn))
+ return 1;
+ J_LOAD_IFIELD(0000);
+ J_LOAD_IFIELD(0001);
+ J_LOAD_IFIELD(0002);
+ J_LOAD_IFIELD(0003);
+ J_LOAD_IFIELD(0004);
+ J_LOAD_IFIELD(0005);
+ J_LOAD_IFIELD(0006);
+ J_LOAD_IFIELD(0007);
+ J_LOAD_IFIELD(0008);
+ J_LOAD_IFIELD(0009);
+ J_LOAD_METHOD(0000);
+
+ return 0;
+}
+
+SIGHT_CLASS_UDEF(Service)
+{
+ sight_unload_class(_E, &_clazzn);
+}
+
+
+SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jlong scm,
+ jstring name,
+ jint access)
+{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ sight_object_t *ns = J2P(scm, sight_object_t *);
+ scm_instance_t *si;
+ SIGHT_ALLOC_CSTRING(name);
+ int rc = 0;
+ int state = SIGHT_SS_DISABLED;
+ char rlpath[PATH_MAX];
+ DIR *rd = NULL;
+
+
+ UNREFERENCED_O;
+ UNREFERENCED(access);
+
+ if (!no || !no->pool) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ if (!ns || !ns->native) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ si = (scm_instance_t *)ns->native;
+ sprintf(rlpath, si->rlpath, si->what);
+
+sretry:
+ if ((rd = opendir(rlpath))) {
+ struct dirent *sent, sbuf;
+ while (!readdir_r(rd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ char smatch[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, rlpath);
+ strcat(sname, sent->d_name);
+ strcpy(smatch, "*/S??");
+ strcat(smatch, J2S(name));
+ /* Match the SnnName */
+ if (!sight_wmatch(sname, smatch)) {
+ SET_IFIELD_S(0001, thiz, sname);
+ SET_IFIELD_S(0004, thiz, sent->d_name);
+
+ /* TODO: Launch script with status param
+ * to figure out the state.
+ */
+ state = SIGHT_SS_UNKNOWN;
+ break;
+ }
+ }
+ closedir(rd);
+ CALL_METHOD1(0000, thiz, state);
+ }
+ if (state == SIGHT_SS_DISABLED &&
+ strcmp(rlpath, "/etc/rcS.d/")) {
+ strcpy(rlpath, "/etc/rcS.d/");
+ goto sretry;
+ }
+ SIGHT_FREE_CSTRING(name);
+ return APR_FROM_OS_ERROR(rc);
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, ctrl0)(SIGHT_STDARGS,
+ jlong instance,
+ jint cmd)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(instance);
+ UNREFERENCED(cmd);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, stats0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, wait0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jlong timeout,
+ jint state)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ UNREFERENCED(timeout);
+ UNREFERENCED(state);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, wait1)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jobject progress,
+ jlong timeout,
+ jint state)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ UNREFERENCED(progress);
+ UNREFERENCED(timeout);
+ UNREFERENCED(state);
+ return APR_ENOTIMPL;
+}
Property changes on: trunk/sight/native/os/solaris/service.c
___________________________________________________________________
Name: svn:eol-style
+ native
17 years, 2 months
JBoss Native SVN: r1099 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 09:41:32 -0400 (Thu, 11 Oct 2007)
New Revision: 1099
Modified:
trunk/sight/native/os/solaris/scm.c
trunk/sight/native/os/solaris/service.c
Log:
Add missing protos
Modified: trunk/sight/native/os/solaris/scm.c
===================================================================
--- trunk/sight/native/os/solaris/scm.c 2007-10-11 13:31:46 UTC (rev 1098)
+++ trunk/sight/native/os/solaris/scm.c 2007-10-11 13:41:32 UTC (rev 1099)
@@ -35,6 +35,8 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <sys/stat.h>
+
static const struct {
const char *flavor; /* Linux flavor */
const char *idpath; /* Path of the init.d scripts */
Modified: trunk/sight/native/os/solaris/service.c
===================================================================
--- trunk/sight/native/os/solaris/service.c 2007-10-11 13:31:46 UTC (rev 1098)
+++ trunk/sight/native/os/solaris/service.c 2007-10-11 13:41:32 UTC (rev 1099)
@@ -146,6 +146,7 @@
scm_instance_t *si;
SIGHT_ALLOC_CSTRING(name);
int rc = 0;
+ int state = SIGHT_SS_DISABLED;
char rlpath[PATH_MAX];
DIR *rd = NULL;
@@ -163,9 +164,10 @@
}
si = (scm_instance_t *)ns->native;
sprintf(rlpath, si->rlpath, si->what);
+
+sretry:
if ((rd = opendir(rlpath))) {
struct dirent *sent, sbuf;
- int state = SIGHT_SS_DISABLED;
while (!readdir_r(rd, &sbuf, &sent)) {
char sname[PATH_MAX];
char smatch[PATH_MAX];
@@ -191,6 +193,11 @@
closedir(rd);
CALL_METHOD1(0000, thiz, state);
}
+ if (state == SIGHT_SS_DISABLED &&
+ strcmp(rlpath, "/etc/rcS.d/")) {
+ strcpy(rlpath, "/etc/rcS.d/");
+ goto sretry;
+ }
SIGHT_FREE_CSTRING(name);
return APR_FROM_OS_ERROR(rc);
}
17 years, 2 months
JBoss Native SVN: r1098 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 09:31:46 -0400 (Thu, 11 Oct 2007)
New Revision: 1098
Modified:
trunk/sight/native/os/solaris/scm.c
trunk/sight/native/os/solaris/service.c
Log:
Add missing protos
Modified: trunk/sight/native/os/solaris/scm.c
===================================================================
--- trunk/sight/native/os/solaris/scm.c 2007-10-11 13:26:30 UTC (rev 1097)
+++ trunk/sight/native/os/solaris/scm.c 2007-10-11 13:31:46 UTC (rev 1098)
@@ -44,7 +44,7 @@
{ "solaris",
"/etc/init.d/",
"/etc/rc%d.d/",
- 5
+ 3
},
{ NULL,
NULL,
Modified: trunk/sight/native/os/solaris/service.c
===================================================================
--- trunk/sight/native/os/solaris/service.c 2007-10-11 13:26:30 UTC (rev 1097)
+++ trunk/sight/native/os/solaris/service.c 2007-10-11 13:31:46 UTC (rev 1098)
@@ -35,6 +35,8 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <sys/stat.h>
+
J_DECLARE_CLAZZ = {
NULL,
NULL,
17 years, 2 months
JBoss Native SVN: r1097 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 09:26:30 -0400 (Thu, 11 Oct 2007)
New Revision: 1097
Added:
trunk/sight/native/os/solaris/scm.c
Modified:
trunk/sight/native/os/solaris/service.c
Log:
Initial Solaris service implementation
Added: trunk/sight/native/os/solaris/scm.c
===================================================================
--- trunk/sight/native/os/solaris/scm.c (rev 0)
+++ trunk/sight/native/os/solaris/scm.c 2007-10-11 13:26:30 UTC (rev 1097)
@@ -0,0 +1,213 @@
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ *
+ */
+
+/**
+ * Service Control Manager implementation
+ *
+ */
+
+#include "sight.h"
+#include "sight_local.h"
+#include "sight_types.h"
+#include "sight_private.h"
+
+static const struct {
+ const char *flavor; /* Linux flavor */
+ const char *idpath; /* Path of the init.d scripts */
+ const char *rlpath; /* Format or the rc0.d ... rc6.d scripts */
+ int rlevel; /* Default run level */
+} scm_paths[] = {
+ { "solaris",
+ "/etc/init.d/",
+ "/etc/rc%d.d/",
+ 5
+ },
+ { NULL,
+ NULL,
+ NULL,
+ 0
+ }
+};
+
+static void scm_cleanup(int mode, sight_object_t *no)
+{
+ if (no && no->native) {
+ scm_instance_t *scm = (scm_instance_t *)no->native;
+ if (scm->services)
+ sight_arr_free(scm->services);
+ free(scm);
+ no->native = NULL;
+ }
+}
+
+
+SIGHT_EXPORT_DECLARE(jint, ServiceControlManager, open0)(SIGHT_STDARGS,
+ jlong instance,
+ jstring database,
+ jint mode)
+{
+ int i = 0;
+ DIR *sd = NULL;
+ scm_instance_t *si;
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ apr_status_t rv;
+
+ UNREFERENCED_O;
+ UNREFERENCED(database);
+ UNREFERENCED(mode);
+
+ if (!no || !no->pool) {
+ return APR_EINVAL;
+ }
+ SIGHT_LOCAL_TRY(no) {
+ if (no->native)
+ scm_cleanup(0, no);
+ if (!(si = (scm_instance_t *)sight_calloc(_E,
+ sizeof(scm_instance_t),
+ THROW_FMARK))) {
+ SIGHT_LOCAL_BRK(no);
+ return apr_get_os_error();
+ }
+ no->native = si;
+ while (scm_paths[i].flavor) {
+ char sname[PATH_MAX];
+ struct stat sb;
+ if ((sd = opendir(scm_paths[i].idpath))) {
+ sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
+ /* Check default run level path */
+ if (stat(sname, &sb) < 0) {
+ closedir(sd);
+ sd = NULL;
+ continue;
+ }
+ si->flavor = scm_paths[i].flavor;
+ si->idpath = scm_paths[i].idpath;
+ si->rlpath = scm_paths[i].rlpath;
+ si->what = scm_paths[i].rlevel;
+ if (!(si->services = sight_arr_new(16))) {
+ rv = apr_get_os_error();
+ closedir(sd);
+ scm_cleanup(0, no);
+ SIGHT_LOCAL_BRK(no);
+ return rv;
+ }
+ break;
+ }
+ i++;
+ }
+ if (sd) {
+ struct dirent *sent, sbuf;
+ while (!readdir_r(sd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, si->idpath);
+ strcat(sname, sent->d_name);
+ if (stat(sname, &sb) < 0)
+ continue;
+ if (!S_ISREG(sb.st_mode))
+ continue;
+ if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+ continue;
+ sight_arr_add(si->services, sent->d_name);
+ }
+ closedir(sd);
+ no->clean = scm_cleanup;
+ rv = APR_SUCCESS;
+ }
+ else {
+ rv = apr_get_os_error();
+ scm_cleanup(0, no);
+ }
+ } SIGHT_LOCAL_END(no);
+ return rv;
+}
+
+SIGHT_EXPORT_DECLARE(void, ServiceControlManager, close0)(SIGHT_STDARGS,
+ jlong instance)
+{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+
+ UNREFERENCED_STDARGS;
+
+ if (no) {
+ scm_cleanup(0, no);
+ no->clean = NULL;
+ }
+}
+
+SIGHT_EXPORT_DECLARE(jobjectArray, ServiceControlManager,
+ enum0)(SIGHT_STDARGS, jlong instance,
+ jint drivers, jint what)
+{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ scm_instance_t *si;
+ jobjectArray ea = NULL;
+ jsize cnt = 0;
+ jint idx = 0;
+
+ UNREFERENCED_O;
+ if (!no || !no->pool || !no->native) {
+ return NULL;
+ }
+ SIGHT_LOCAL_TRY(no) {
+ if (drivers) {
+ /* There are no drivers on linux ?
+ * Perhaps we should have here the kernel modules
+ */
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
+ }
+ si = (scm_instance_t *)no->native;
+ if (what > 0)
+ si->what = what;
+ if (si->services && si->services->siz) {
+ jint i;
+ /* TODO: Calculate size according to the flags */
+ cnt = si->services->siz;
+ ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
+ if (!ea || (*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
+ }
+ for (i = 0; i < cnt; i++) {
+ jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ if (s)
+ (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
+ else
+ break;
+ if ((*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ break;
+ }
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+ } SIGHT_LOCAL_END(no);
+ return ea;
+}
Property changes on: trunk/sight/native/os/solaris/scm.c
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/sight/native/os/solaris/service.c
===================================================================
--- trunk/sight/native/os/solaris/service.c 2007-10-11 07:56:42 UTC (rev 1096)
+++ trunk/sight/native/os/solaris/service.c 2007-10-11 13:26:30 UTC (rev 1097)
@@ -1,198 +1,244 @@
-/*
- * SIGHT - System information gathering hybrid tool
- *
- * Copyright(c) 2007 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Mladen Turk
- *
- */
-
-/**
- * Service implementation
- *
- */
-
-#include "sight.h"
-#include "sight_local.h"
-#include "sight_types.h"
-#include "sight_private.h"
-
-J_DECLARE_CLAZZ = {
- NULL,
- NULL,
- SIGHT_CLASS_PATH "Service"
-};
-
-J_DECLARE_F_ID(0000) = {
- NULL,
- "Name",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0001) = {
- NULL,
- "BinaryPathName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0002) = {
- NULL,
- "Dependencies",
- "[Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0003) = {
- NULL,
- "ServiceStartName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0004) = {
- NULL,
- "DisplayName",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0005) = {
- NULL,
- "Description",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0006) = {
- NULL,
- "LoadOrderGroup",
- "Ljava/lang/String;"
-};
-
-J_DECLARE_F_ID(0007) = {
- NULL,
- "ExitCode",
- "I"
-};
-
-J_DECLARE_F_ID(0008) = {
- NULL,
- "ServiceSpecificExitCode",
- "I"
-};
-
-J_DECLARE_F_ID(0009) = {
- NULL,
- "ProcessId",
- "I"
-};
-
-J_DECLARE_M_ID(0000) = {
- NULL,
- "setState",
- "(I)V"
-};
-
-SIGHT_CLASS_LDEF(Service)
-{
- if (sight_load_class(_E, &_clazzn))
- return 1;
- J_LOAD_IFIELD(0000);
- J_LOAD_IFIELD(0001);
- J_LOAD_IFIELD(0002);
- J_LOAD_IFIELD(0003);
- J_LOAD_IFIELD(0004);
- J_LOAD_IFIELD(0005);
- J_LOAD_IFIELD(0006);
- J_LOAD_IFIELD(0007);
- J_LOAD_IFIELD(0008);
- J_LOAD_IFIELD(0009);
- J_LOAD_METHOD(0000);
-
- return 0;
-}
-
-SIGHT_CLASS_UDEF(Service)
-{
- sight_unload_class(_E, &_clazzn);
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jlong scm,
- jstring name,
- jint access)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(scm);
- UNREFERENCED(name);
- UNREFERENCED(access);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, ctrl0)(SIGHT_STDARGS,
- jlong instance,
- jint cmd)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(instance);
- UNREFERENCED(cmd);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, stats0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, wait0)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jlong timeout,
- jint state)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(timeout);
- UNREFERENCED(state);
- return APR_ENOTIMPL;
-}
-
-SIGHT_EXPORT_DECLARE(jint, Service, wait1)(SIGHT_STDARGS,
- jobject thiz,
- jlong instance,
- jobject progress,
- jlong timeout,
- jint state)
-{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(instance);
- UNREFERENCED(progress);
- UNREFERENCED(timeout);
- UNREFERENCED(state);
- return APR_ENOTIMPL;
-}
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ *
+ */
+
+/**
+ * Service implementation
+ *
+ */
+
+#include "sight.h"
+#include "sight_local.h"
+#include "sight_types.h"
+#include "sight_private.h"
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ SIGHT_CLASS_PATH "Service"
+};
+
+J_DECLARE_F_ID(0000) = {
+ NULL,
+ "Name",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0001) = {
+ NULL,
+ "BinaryPathName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0002) = {
+ NULL,
+ "Dependencies",
+ "[Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0003) = {
+ NULL,
+ "ServiceStartName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0004) = {
+ NULL,
+ "DisplayName",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0005) = {
+ NULL,
+ "Description",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0006) = {
+ NULL,
+ "LoadOrderGroup",
+ "Ljava/lang/String;"
+};
+
+J_DECLARE_F_ID(0007) = {
+ NULL,
+ "ExitCode",
+ "I"
+};
+
+J_DECLARE_F_ID(0008) = {
+ NULL,
+ "ServiceSpecificExitCode",
+ "I"
+};
+
+J_DECLARE_F_ID(0009) = {
+ NULL,
+ "ProcessId",
+ "I"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "setState",
+ "(I)V"
+};
+
+SIGHT_CLASS_LDEF(Service)
+{
+ if (sight_load_class(_E, &_clazzn))
+ return 1;
+ J_LOAD_IFIELD(0000);
+ J_LOAD_IFIELD(0001);
+ J_LOAD_IFIELD(0002);
+ J_LOAD_IFIELD(0003);
+ J_LOAD_IFIELD(0004);
+ J_LOAD_IFIELD(0005);
+ J_LOAD_IFIELD(0006);
+ J_LOAD_IFIELD(0007);
+ J_LOAD_IFIELD(0008);
+ J_LOAD_IFIELD(0009);
+ J_LOAD_METHOD(0000);
+
+ return 0;
+}
+
+SIGHT_CLASS_UDEF(Service)
+{
+ sight_unload_class(_E, &_clazzn);
+}
+
+
+SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jlong scm,
+ jstring name,
+ jint access)
+{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+ sight_object_t *ns = J2P(scm, sight_object_t *);
+ scm_instance_t *si;
+ SIGHT_ALLOC_CSTRING(name);
+ int rc = 0;
+ char rlpath[PATH_MAX];
+ DIR *rd = NULL;
+
+
+ UNREFERENCED_O;
+ UNREFERENCED(access);
+
+ if (!no || !no->pool) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ if (!ns || !ns->native) {
+ SIGHT_FREE_CSTRING(name);
+ return APR_EINVAL;
+ }
+ si = (scm_instance_t *)ns->native;
+ sprintf(rlpath, si->rlpath, si->what);
+ if ((rd = opendir(rlpath))) {
+ struct dirent *sent, sbuf;
+ int state = SIGHT_SS_DISABLED;
+ while (!readdir_r(rd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ char smatch[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, rlpath);
+ strcat(sname, sent->d_name);
+ strcpy(smatch, "*/S??");
+ strcat(smatch, J2S(name));
+ /* Match the SnnName */
+ if (!sight_wmatch(sname, smatch)) {
+ SET_IFIELD_S(0001, thiz, sname);
+ SET_IFIELD_S(0004, thiz, sent->d_name);
+
+ /* TODO: Launch script with status param
+ * to figure out the state.
+ */
+ state = SIGHT_SS_UNKNOWN;
+ break;
+ }
+ }
+ closedir(rd);
+ CALL_METHOD1(0000, thiz, state);
+ }
+ SIGHT_FREE_CSTRING(name);
+ return APR_FROM_OS_ERROR(rc);
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, ctrl0)(SIGHT_STDARGS,
+ jlong instance,
+ jint cmd)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(instance);
+ UNREFERENCED(cmd);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, stats0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, wait0)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jlong timeout,
+ jint state)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ UNREFERENCED(timeout);
+ UNREFERENCED(state);
+ return APR_ENOTIMPL;
+}
+
+SIGHT_EXPORT_DECLARE(jint, Service, wait1)(SIGHT_STDARGS,
+ jobject thiz,
+ jlong instance,
+ jobject progress,
+ jlong timeout,
+ jint state)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(thiz);
+ UNREFERENCED(instance);
+ UNREFERENCED(progress);
+ UNREFERENCED(timeout);
+ UNREFERENCED(state);
+ return APR_ENOTIMPL;
+}
17 years, 2 months
JBoss Native SVN: r1096 - trunk/sight/test/org/jboss/sight.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 03:56:42 -0400 (Thu, 11 Oct 2007)
New Revision: 1096
Modified:
trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
Log:
Use larger number of objects to test
Modified: trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-11 07:55:20 UTC (rev 1095)
+++ trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-11 07:56:42 UTC (rev 1096)
@@ -116,7 +116,7 @@
throws Exception
{
- for (int i = 0; i < 500; i++) {
+ for (int i = 0; i < 500000; i++) {
new NativeObjectTestClass();
}
// Library.clear() will force that all native objects
17 years, 2 months
JBoss Native SVN: r1095 - in trunk/sight: test/org/jboss/sight and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 03:55:20 -0400 (Thu, 11 Oct 2007)
New Revision: 1095
Modified:
trunk/sight/native/share/library.c
trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
Log:
Use NESTED thread mutexes
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-11 06:57:32 UTC (rev 1094)
+++ trunk/sight/native/share/library.c 2007-10-11 07:55:20 UTC (rev 1095)
@@ -175,7 +175,7 @@
return JNI_FALSE;
}
if (apr_thread_mutex_create(&sight_global_mutex,
- APR_THREAD_MUTEX_DEFAULT,
+ APR_THREAD_MUTEX_NESTED,
sight_master_pool) != APR_SUCCESS) {
return JNI_FALSE;
}
@@ -216,7 +216,7 @@
}
if (lockable) {
if ((rc = apr_thread_mutex_create(&mutex,
- APR_THREAD_MUTEX_DEFAULT,
+ APR_THREAD_MUTEX_NESTED,
sight_master_pool)) != APR_SUCCESS) {
apr_allocator_destroy(allocator);
*pool = NULL;
Modified: trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-11 06:57:32 UTC (rev 1094)
+++ trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-11 07:55:20 UTC (rev 1095)
@@ -116,7 +116,7 @@
throws Exception
{
- for (int i = 0; i < 500000; i++) {
+ for (int i = 0; i < 500; i++) {
new NativeObjectTestClass();
}
// Library.clear() will force that all native objects
17 years, 2 months
JBoss Native SVN: r1094 - in trunk/sight: native/include and 2 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-11 02:57:32 -0400 (Thu, 11 Oct 2007)
New Revision: 1094
Modified:
trunk/sight/java/org/jboss/sight/File.java
trunk/sight/java/org/jboss/sight/NativeObject.java
trunk/sight/native/include/sight_local.h
trunk/sight/native/include/sight_types.h
trunk/sight/native/share/library.c
trunk/sight/native/share/no.c
trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
Log:
Fix NativeObject GC
Modified: trunk/sight/java/org/jboss/sight/File.java
===================================================================
--- trunk/sight/java/org/jboss/sight/File.java 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/java/org/jboss/sight/File.java 2007-10-11 06:57:32 UTC (rev 1094)
@@ -230,6 +230,9 @@
return tmp;
}
+ /**
+ * Initialize console stream Files
+ */
protected static void initializeStdFiles()
{
try {
Modified: trunk/sight/java/org/jboss/sight/NativeObject.java
===================================================================
--- trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-11 06:57:32 UTC (rev 1094)
@@ -50,6 +50,8 @@
throws OutOfMemoryError;
private static native void intr0(long instance);
+ private static native void sleep0(long instance, long step, long time);
+
/**
* Create new NativeObject without APR pool
*/
@@ -139,6 +141,11 @@
cbset0(INSTANCE, callback);
}
+ public void sleep(long step, long time)
+ {
+ sleep0(INSTANCE, step, time);
+ }
+
/**
* Destroy callback method.
* <BR/>
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/native/include/sight_local.h 2007-10-11 06:57:32 UTC (rev 1094)
@@ -361,8 +361,10 @@
/* XXX : BSD as more */
} sight_procstate_e;
-apr_status_t sight_pool_create(apr_pool_t **, apr_pool_t *, int);
+apr_status_t sight_pool_create(apr_pool_t **, apr_thread_mutex_t **,
+ apr_pool_t *, int);
apr_status_t sight_pool_clear(apr_pool_t *);
+apr_status_t sight_pool_destroy(apr_pool_t *);
apr_status_t sight_pool_lock(apr_thread_mutex_t **, apr_pool_t *);
apr_status_t sight_pool_lock_parent(apr_thread_mutex_t **, apr_pool_t *);
@@ -410,8 +412,10 @@
extern volatile apr_uint64_t sight_cnt_native_alloc;
extern volatile apr_uint64_t sight_cnt_native_create;
extern volatile apr_uint64_t sight_cnt_native_free;
+extern volatile apr_uint64_t sight_cnt_native_destroyed;
extern volatile apr_uint64_t sight_cnt_native_pcleanup;
extern volatile apr_uint64_t sight_cnt_native_clear;
+extern volatile apr_uint64_t sight_cnt_native_cleared;
extern volatile apr_uint64_t sight_cnt_native_clrcall;
extern void dbprintf(char *format, ...);
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/native/include/sight_types.h 2007-10-11 06:57:32 UTC (rev 1094)
@@ -117,13 +117,14 @@
volatile apr_uint32_t refcount;
#endif
volatile apr_uint32_t interrupted;
- apr_pool_t *pool;
- void *native;
- void *opaque;
- jobject object;
- jmethodID destroy;
- sight_callback_t cb;
- void (*clean)(int, sight_object_t *);
+ apr_pool_t *pool;
+ apr_thread_mutex_t *mutex;
+ void *native;
+ void *opaque;
+ jobject object;
+ jmethodID destroy;
+ sight_callback_t cb;
+ void (*clean)(int, sight_object_t *);
};
#define CACHE_HASH_MASK 255
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/native/share/library.c 2007-10-11 06:57:32 UTC (rev 1094)
@@ -32,6 +32,7 @@
#include "apr_atomic.h"
#include "sight_version.h"
+apr_pool_t *sight_master_pool = NULL;
apr_pool_t *sight_global_pool = NULL;
apr_pool_t *sight_temp_pool = NULL;
static JavaVM *sight_global_vm = NULL;
@@ -45,8 +46,10 @@
volatile apr_uint64_t sight_cnt_native_alloc = 0;
volatile apr_uint64_t sight_cnt_native_create = 0;
volatile apr_uint64_t sight_cnt_native_free = 0;
+volatile apr_uint64_t sight_cnt_native_destroyed = 0;
volatile apr_uint64_t sight_cnt_native_pcleanup = 0;
volatile apr_uint64_t sight_cnt_native_clear = 0;
+volatile apr_uint64_t sight_cnt_native_cleared = 0;
volatile apr_uint64_t sight_cnt_native_clrcall = 0;
static volatile apr_uint64_t sight_cnt_jvm_attached = 0;
@@ -168,18 +171,22 @@
sight_unload_classes(_E);
return JNI_FALSE;
}
- if (sight_pool_create(&sight_global_pool, NULL, 1) != APR_SUCCESS) {
+ if (apr_pool_create(&sight_master_pool, NULL) != APR_SUCCESS) {
return JNI_FALSE;
}
- if (sight_pool_create(&sight_temp_pool, NULL, 1) != APR_SUCCESS) {
+ if (apr_thread_mutex_create(&sight_global_mutex,
+ APR_THREAD_MUTEX_DEFAULT,
+ sight_master_pool) != APR_SUCCESS) {
return JNI_FALSE;
}
- if (apr_thread_mutex_create(&sight_global_mutex,
- APR_THREAD_MUTEX_DEFAULT,
- sight_global_pool) != APR_SUCCESS) {
+ if (sight_pool_create(&sight_global_pool, NULL, NULL, 1) != APR_SUCCESS) {
return JNI_FALSE;
}
+ if (sight_pool_create(&sight_temp_pool, NULL, NULL, 1) != APR_SUCCESS) {
+ return JNI_FALSE;
+ }
+
apr_atomic_init(sight_global_pool);
if (sight_main(sight_global_pool) != APR_SUCCESS) {
apr_pool_destroy(sight_temp_pool);
@@ -192,8 +199,8 @@
return JNI_TRUE;
}
-apr_status_t sight_pool_create(apr_pool_t **pool, apr_pool_t *parent,
- int lockable)
+apr_status_t sight_pool_create(apr_pool_t **pool, apr_thread_mutex_t **lock,
+ apr_pool_t *parent, int lockable)
{
apr_status_t rc;
apr_allocator_t *allocator = NULL;
@@ -210,12 +217,13 @@
if (lockable) {
if ((rc = apr_thread_mutex_create(&mutex,
APR_THREAD_MUTEX_DEFAULT,
- *pool)) != APR_SUCCESS) {
+ sight_master_pool)) != APR_SUCCESS) {
apr_allocator_destroy(allocator);
*pool = NULL;
return rc;
}
-
+ if (lock)
+ *lock = mutex;
}
else if (parent) {
/* Use parents allocator mutex */
@@ -228,23 +236,30 @@
apr_status_t sight_pool_clear(apr_pool_t *pool)
{
- apr_status_t rc;
apr_allocator_t *allocator = apr_pool_allocator_get(pool);
apr_thread_mutex_t *mutex = apr_allocator_mutex_get(allocator);
+ if (mutex)
+ apr_thread_mutex_lock(mutex);
apr_pool_clear(pool);
- if (mutex) {
- mutex = NULL;
- if ((rc = apr_thread_mutex_create(&mutex,
- APR_THREAD_MUTEX_DEFAULT,
- pool)) != APR_SUCCESS) {
- return rc;
- }
- }
- apr_allocator_mutex_set(allocator, mutex);
+ if (mutex)
+ apr_thread_mutex_unlock(mutex);
return APR_SUCCESS;
}
+apr_status_t sight_pool_destroy(apr_pool_t *pool)
+{
+ apr_allocator_t *allocator = apr_pool_allocator_get(pool);
+ apr_thread_mutex_t *mutex = apr_allocator_mutex_get(allocator);
+
+ if (mutex)
+ apr_thread_mutex_lock(mutex);
+ apr_pool_destroy(pool);
+ if (mutex)
+ apr_thread_mutex_unlock(mutex);
+ return APR_SUCCESS;
+}
+
apr_status_t sight_pool_lock(apr_thread_mutex_t **mutex, apr_pool_t *pool)
{
if (pool) {
@@ -268,8 +283,9 @@
apr_pool_t *parent = apr_pool_parent_get(pool);
apr_allocator_t *allocator = apr_pool_allocator_get(parent);
- if ((*mutex = apr_allocator_mutex_get(allocator)) != NULL)
+ if ((*mutex = apr_allocator_mutex_get(allocator)) != NULL) {
return apr_thread_mutex_lock(*mutex);
+ }
}
*mutex = NULL;
return APR_SUCCESS;
@@ -281,8 +297,10 @@
fprintf(stderr, "Allocated : %" APR_INT64_T_FMT "\n", sight_cnt_native_alloc);
fprintf(stderr, "Initialized : %" APR_INT64_T_FMT "\n", sight_cnt_native_create);
fprintf(stderr, "Garbage collected : %" APR_INT64_T_FMT "\n", sight_cnt_native_free);
+ fprintf(stderr, "Garbage destroyed : %" APR_INT64_T_FMT "\n", sight_cnt_native_destroyed);
fprintf(stderr, "Pool cleanup destroyed : %" APR_INT64_T_FMT "\n", sight_cnt_native_pcleanup);
- fprintf(stderr, "Cleared : %" APR_INT64_T_FMT "\n", sight_cnt_native_clear);
+ fprintf(stderr, "Clear called : %" APR_INT64_T_FMT "\n", sight_cnt_native_clear);
+ fprintf(stderr, "Cleared : %" APR_INT64_T_FMT "\n", sight_cnt_native_cleared);
fprintf(stderr, "Clean callbacks : %" APR_INT64_T_FMT "\n", sight_cnt_native_clrcall);
fprintf(stderr, "\nJVM statistics ...............\n");
@@ -302,6 +320,8 @@
UNREFERENCED_STDARGS;
if (sight_global_pool) {
+ apr_thread_mutex_t *glock;
+ apr_thread_mutex_t *tlock;
#if SIGHT_APR_REFCOUNT
apr_uint32_t ioc = 0;
apr_uint32_t in_object_count = apr_atomic_dec32(sight_global_atomic);
@@ -310,8 +330,8 @@
fprintf(stderr, "\nLibrary terminate ............\n");
fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
#endif
- sight_pool_lock(NULL, sight_temp_pool);
- sight_pool_lock(NULL, sight_global_pool);
+ sight_pool_lock(&tlock, sight_temp_pool);
+ sight_pool_lock(&glock, sight_global_pool);
#if SIGHT_APR_REFCOUNT
/* Wait until all JNI calls are done
@@ -337,9 +357,13 @@
}
#endif
apr_pool_destroy(sight_temp_pool);
+ sight_temp_pool = NULL;
apr_pool_destroy(sight_global_pool);
- sight_temp_pool = NULL;
sight_global_pool = NULL;
+ apr_thread_mutex_unlock(tlock);
+ apr_thread_mutex_unlock(glock);
+ apr_sleep(1000L);
+ apr_pool_destroy(sight_master_pool);
apr_terminate();
sight_unload_classes(_E);
}
@@ -348,6 +372,58 @@
#endif
}
+SIGHT_EXPORT_DECLARE(void, Library, clear0)(SIGHT_STDARGS)
+{
+
+ UNREFERENCED_O;
+
+ if (sight_global_pool) {
+#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
+ apr_uint32_t in_object_count = apr_atomic_dec32(sight_global_atomic);
+#endif
+ /* Wait untill all object native calls are finished */
+#ifdef SIGHT_DO_STATS
+ fprintf(stderr, "\nLibrary clear ................\n");
+ fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
+#endif
+
+#if SIGHT_APR_REFCOUNT
+
+ while (in_object_count) {
+ apr_thread_yield();
+ in_object_count = apr_atomic_read32(sight_global_atomic);
+ }
+ if (ioc++ > OPTIMISTIC_LOCK_CNT) {
+ /* Sleep one millisecond */
+ apr_sleep(1000L);
+ }
+ if (ioc > OPTIMISTIC_LOCK_MAX) {
+ /* TODO: We have a zombie or a lengthy JNI op.
+ * Find a way to bail out without crushing JVM
+ */
+#ifdef SIGHT_DO_STATS
+ fprintf(stderr, "Library.clear0() call is locked ...\n");
+ fprintf(stderr, "Bailing out !\n");
+ fflush(stderr);
+#endif
+ throwAprException(_E, APR_TIMEUP);
+ return;
+ }
+
+#endif
+
+ sight_pool_clear(sight_temp_pool);
+ sight_pool_clear(sight_global_pool);
+ /* Sleep one second */
+ apr_sleep(1000L);
+ apr_atomic_set32(sight_global_atomic, 1);
+ }
+#ifdef SIGHT_DO_STATS
+ dump_stats();
+#endif
+}
+
SIGHT_EXPORT_DECLARE(jint, Library, version)(SIGHT_STDARGS, jint what)
{
apr_version_t apv;
@@ -400,64 +476,7 @@
return CSTR_TO_JSTRING(apr_version_string());
}
-SIGHT_EXPORT_DECLARE(void, Library, clear0)(SIGHT_STDARGS)
-{
- apr_status_t rc;
- UNREFERENCED_O;
- if (sight_global_pool) {
-#if SIGHT_APR_REFCOUNT
- apr_uint32_t ioc = 0;
- apr_uint32_t in_object_count = apr_atomic_dec32(sight_global_atomic);
-#endif
- /* Wait untill all object native calls are finished */
-#ifdef SIGHT_DO_STATS
- fprintf(stderr, "\nLibrary clear ................\n");
- fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
-#endif
- sight_pool_lock(NULL, sight_temp_pool);
- sight_pool_lock(NULL, sight_global_pool);
-
-#if SIGHT_APR_REFCOUNT
-
- while (in_object_count) {
- apr_thread_yield();
- in_object_count = apr_atomic_read32(sight_global_atomic);
- }
- if (ioc++ > OPTIMISTIC_LOCK_CNT) {
- /* Sleep one millisecond */
- apr_sleep(1000L);
- }
- if (ioc > OPTIMISTIC_LOCK_MAX) {
- /* TODO: We have a zombie or a lengthy JNI op.
- * Find a way to bail out without crushing JVM
- */
-#ifdef SIGHT_DO_STATS
- fprintf(stderr, "Library.clear0() call is locked ...\n");
- fprintf(stderr, "Bailing out !\n");
- fflush(stderr);
-#endif
- throwAprException(_E, APR_TIMEUP);
- return;
- }
-
-#endif
-
- sight_pool_clear(sight_temp_pool);
- sight_pool_clear(sight_global_pool);
- apr_atomic_set32(sight_global_atomic, 1);
- if ((rc = apr_thread_mutex_create(&sight_global_mutex,
- APR_THREAD_MUTEX_DEFAULT,
- sight_global_pool)) != APR_SUCCESS) {
- throwAprException(_E, rc);
- return;
- }
- }
-#ifdef SIGHT_DO_STATS
- dump_stats();
-#endif
-}
-
/* Get current JNIEnv
* If this is a thread not created by JVM attach the thread
*/
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/native/share/no.c 2007-10-11 06:57:32 UTC (rev 1094)
@@ -87,6 +87,9 @@
JNIEnv *_E = NULL;
jint em = sight_get_jnienv(&_E);
+ apr_atomic_inc32(&no->interrupted);
+ /* Mark the pool as invaild */
+ no->pool = NULL;
if (_E && no->object) {
jobject object = (*_E)->NewLocalRef(_E, no->object);
(*_E)->DeleteWeakGlobalRef(_E, no->object);
@@ -101,13 +104,11 @@
no->object);
}
}
- SET_IFIELD_J(0000, no->object, 0);
SET_IFIELD_J(0001, no->object, 0);
(*_E)->DeleteLocalRef(_E, no->object);
no->object = NULL;
}
}
- apr_atomic_inc32(&no->interrupted);
#if SIGHT_APR_REFCOUNT
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
@@ -127,12 +128,13 @@
#endif
if (no->clean) {
(*no->clean)(POOL_CALLBACK, no);
+ no->clean = NULL;
}
if (_E && no->cb.object) {
(*_E)->DeleteGlobalRef(_E, no->cb.object);
+ no->cb.object = NULL;
}
sight_clr_jnienv(em);
- free(no);
}
return rv;
}
@@ -180,9 +182,17 @@
ppool = sight_global_pool;
}
if ((rc = sight_pool_lock(&mutex, ppool)) == APR_SUCCESS) {
- if ((rc = sight_pool_create(&pool, ppool, lock)) != APR_SUCCESS) {
+ if (!sight_global_pool) {
+ /* Global pool is destroyed */
throwAprMemoryException(_E, THROW_FMARK, rc);
apr_thread_mutex_unlock(mutex);
+ }
+ /* TODO: How to detect if parent pool was destroyed?
+ */
+ if ((rc = sight_pool_create(&pool, &no->mutex, ppool,
+ lock)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ apr_thread_mutex_unlock(mutex);
return;
}
@@ -247,7 +257,16 @@
return;
/* Check if parent is locked */
if (sight_pool_lock_parent(&mutex, no->pool) == APR_SUCCESS) {
+ apr_pool_t *pool = no->pool;
+#ifdef SIGHT_DO_STATS
+ sight_cnt_native_destroyed++;
+#endif
apr_atomic_inc32(&no->interrupted);
+ if (no->mutex) {
+ /* Lock only if we are the owner of the mutex */
+ apr_thread_mutex_lock(no->mutex);
+ }
+ no->pool = NULL;
if (no->object) {
object = (*_E)->NewLocalRef(_E, no->object);
(*_E)->DeleteWeakGlobalRef(_E, no->object);
@@ -275,8 +294,8 @@
}
}
#endif
- if (no->pool)
- apr_pool_cleanup_kill(no->pool, no, native_object_cleanup);
+ if (pool)
+ apr_pool_cleanup_kill(pool, no, native_object_cleanup);
if (no->object) {
(*_E)->CallVoidMethod(_E, no->object, no->destroy, NULL);
if ((*_E)->ExceptionCheck(_E)) {
@@ -286,12 +305,20 @@
}
if (no->clean)
(*no->clean)(POOL_DESTROY, no);
- if (no->pool)
- apr_pool_destroy(no->pool);
+ if (pool)
+ sight_pool_destroy(pool);
if (object)
(*_E)->DeleteLocalRef(_E, object);
- if (no->cb.object)
+ if (no->cb.object) {
(*_E)->DeleteGlobalRef(_E, no->cb.object);
+ no->cb.object = NULL;
+ }
+ if (no->mutex) {
+ apr_thread_mutex_unlock(no->mutex);
+ /* XXX: Check if we need some larger timeout here */
+ apr_thread_yield();
+ apr_thread_mutex_destroy(no->mutex);
+ }
if (mutex)
apr_thread_mutex_unlock(mutex);
free(no);
@@ -314,8 +341,22 @@
#endif
if (!no)
return;
+ /* Lock the parent pool.
+ * If the parent pool is inside clear or destroy
+ * this call will block until finished.
+ * By that time all pool cleanups will be run and
+ * the objects pool will be set to zero
+ */
if (sight_pool_lock_parent(&mutex, no->pool) == APR_SUCCESS) {
+ apr_pool_t *pool = no->pool;
+#ifdef SIGHT_DO_STATS
+ sight_cnt_native_cleared++;
+#endif
apr_atomic_inc32(&no->interrupted);
+ if (no->mutex) {
+ /* Lock only if we are the owner of the mutex */
+ apr_thread_mutex_lock(no->mutex);
+ }
#if SIGHT_APR_REFCOUNT
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
@@ -351,9 +392,11 @@
no->opaque = NULL;
no->native = NULL;
}
- apr_atomic_set32(&no->interrupted, 0);
+ if (no->mutex)
+ apr_thread_mutex_unlock(no->mutex);
if (mutex)
apr_thread_mutex_unlock(mutex);
+ apr_atomic_set32(&no->interrupted, 0);
}
}
@@ -367,3 +410,28 @@
apr_atomic_inc32(&no->interrupted);
}
}
+
+/* Temporary debug method for testing long native operations
+ */
+SIGHT_EXPORT_DECLARE(void, NativeObject, sleep0)(SIGHT_STDARGS,
+ jlong instance,
+ jlong step,
+ jlong time)
+{
+ sight_object_t *no = J2P(instance, sight_object_t *);
+
+ UNREFERENCED_STDARGS;
+ if (!no)
+ return;
+ SIGHT_LOCAL_TRY(no) {
+ jlong i;
+ for (i = 0; i < step; i++) {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return;
+ }
+ apr_sleep(J2T(time));
+ }
+
+ } SIGHT_LOCAL_END(no);
+}
Modified: trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-10 06:28:46 UTC (rev 1093)
+++ trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-11 06:57:32 UTC (rev 1094)
@@ -45,7 +45,7 @@
super(0);
created++;
}
-
+
// Called from the native when the
// object is destroyed.
protected void onDestroy()
@@ -55,6 +55,46 @@
}
+ class NativeObjectRunner extends Thread
+ {
+ NativeObjectTestClass no;
+
+ NativeObjectRunner(NativeObjectTestClass no)
+ {
+ this.no = no;
+ }
+
+ public void run() {
+ try {
+ // Sleep 100 * 10 ms
+ no.sleep(100, 10000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ class NativeObjectCleaner extends Thread
+ {
+ NativeObjectTestClass[] no;
+
+ NativeObjectCleaner(NativeObjectTestClass[] no)
+ {
+ this.no = no;
+ }
+
+ public void run() {
+ try {
+ for (int i = 0; i < no.length; i++) {
+ if (no[i] != null)
+ no[i].clear();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
public static void main(String[] args)
{
junit.textui.TestRunner.run(MemoryLeakTest.class);
@@ -72,11 +112,11 @@
Library.shutdown();
}
- public void testNativeObject()
+ public void testNativeObject0()
throws Exception
{
- for (int i = 0; i < 1000000; i++) {
+ for (int i = 0; i < 500000; i++) {
new NativeObjectTestClass();
}
// Library.clear() will force that all native objects
@@ -85,4 +125,64 @@
assertEquals(created, destroyed);
}
+ public void testNativeCalls1()
+ throws Exception
+ {
+
+ for (int i = 0; i < 1000; i++) {
+ new NativeObjectRunner(new NativeObjectTestClass()).start();
+ }
+ // Library.clear() will force that all native objects
+ // gets destroyed.
+ Library.clear();
+ assertEquals(created, destroyed);
+ }
+
+ public void testNativeCalls2()
+ throws Exception
+ {
+ int i;
+ NativeObjectTestClass[] no = new NativeObjectTestClass[1000];
+ for (i = 0; i < 1000; i++) {
+ no[i] = new NativeObjectTestClass();
+ }
+ for (i = 0; i < 1000; i++) {
+ new NativeObjectRunner(no[i]).start();
+ }
+ for (i = 0; i < 1000; i++) {
+ no[i].clear();
+ }
+
+ // Library.clear() will force that all native objects
+ // gets destroyed.
+ Library.clear();
+ assertEquals(created, destroyed);
+ }
+
+ public void testNativeCalls3()
+ throws Exception
+ {
+ int i;
+ NativeObjectTestClass[] no = new NativeObjectTestClass[1000];
+ for (i = 0; i < 1000; i++) {
+ no[i] = new NativeObjectTestClass();
+ }
+ for (i = 0; i < 1000; i++) {
+ new NativeObjectRunner(no[i]).start();
+ }
+ for (i = 0; i < 10; i++) {
+ new NativeObjectCleaner(no).start();
+ }
+ // Library.clear() will force that all native objects
+ // gets destroyed.
+ Library.clear();
+ assertEquals(created, destroyed);
+ for (i = 0; i < 1000; i++) {
+ no[i] = null;
+ }
+ System.gc();
+ Thread.sleep(1000);
+ System.gc();
+ }
+
}
17 years, 2 months
JBoss Native SVN: r1093 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-10 02:28:46 -0400 (Wed, 10 Oct 2007)
New Revision: 1093
Modified:
trunk/sight/native/share/no.c
Log:
Remove redundant code. Poool is tested in sight_pool_lock
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-09 11:41:45 UTC (rev 1092)
+++ trunk/sight/native/share/no.c 2007-10-10 06:28:46 UTC (rev 1093)
@@ -179,11 +179,6 @@
/* Use the global pool */
ppool = sight_global_pool;
}
- if (!ppool) {
- /* Global pool is missing */
- throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
- return;
- }
if ((rc = sight_pool_lock(&mutex, ppool)) == APR_SUCCESS) {
if ((rc = sight_pool_create(&pool, ppool, lock)) != APR_SUCCESS) {
throwAprMemoryException(_E, THROW_FMARK, rc);
17 years, 2 months
JBoss Native SVN: r1092 - in trunk/sight: native/include and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-09 07:41:45 -0400 (Tue, 09 Oct 2007)
New Revision: 1092
Modified:
trunk/sight/java/org/jboss/sight/NativeObject.java
trunk/sight/java/org/jboss/sight/Pool.java
trunk/sight/native/include/sight_local.h
trunk/sight/native/share/dir.c
trunk/sight/native/share/file.c
trunk/sight/native/share/finfo.c
trunk/sight/native/share/library.c
trunk/sight/native/share/no.c
Log:
Use thread locks instead atomics for pool GC
Modified: trunk/sight/java/org/jboss/sight/NativeObject.java
===================================================================
--- trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/java/org/jboss/sight/NativeObject.java 2007-10-09 11:41:45 UTC (rev 1092)
@@ -41,7 +41,8 @@
private static native long alloc()
throws OutOfMemoryError;
private static native void init0(NativeObject thiz,
- long instance, long parent)
+ long instance, long parent,
+ boolean lockable)
throws OutOfMemoryError;
private static native void free0(long instance);
private static native void clear0(long instance);
@@ -65,16 +66,30 @@
* pool. If it is non-zero, the new pool will inherit all
* of its parent pool's attributes, except the apr_pool_t will
* be a sub-pool.
+ * @param lockable Defines if the created object can have child objects
*/
- protected NativeObject(long parent)
+ protected NativeObject(long parent, boolean lockable)
throws OutOfMemoryError
{
POOL = 0;
INSTANCE = alloc();
- init0(this, INSTANCE, parent);
+ init0(this, INSTANCE, parent, lockable);
}
/**
+ * Create new NativeObject
+ * @param parent The parent pool. If this is 0, the new pool is a root
+ * pool. If it is non-zero, the new pool will inherit all
+ * of its parent pool's attributes, except the apr_pool_t will
+ * be a sub-pool.
+ */
+ protected NativeObject(long parent)
+ throws OutOfMemoryError
+ {
+ this(parent, false);
+ }
+
+ /**
* Interrupt the pending native operation.
*/
public void interrupt()
@@ -87,9 +102,11 @@
*/
public void destroy()
{
- free0(INSTANCE);
- INSTANCE = 0;
- POOL = 0;
+ synchronized(this) {
+ free0(INSTANCE);
+ INSTANCE = 0;
+ POOL = 0;
+ }
}
/**
@@ -97,7 +114,9 @@
*/
public void clear()
{
- clear0(INSTANCE);
+ synchronized(this) {
+ clear0(INSTANCE);
+ }
}
/**
Modified: trunk/sight/java/org/jboss/sight/Pool.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Pool.java 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/java/org/jboss/sight/Pool.java 2007-10-09 11:41:45 UTC (rev 1092)
@@ -45,7 +45,7 @@
*/
public Pool()
{
- super(0);
+ super(0, true);
}
/**
@@ -57,7 +57,7 @@
*/
public Pool(Pool parent)
{
- super(parent.POOL);
+ super(parent.POOL, true);
}
protected void onDestroy()
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/include/sight_local.h 2007-10-09 11:41:45 UTC (rev 1092)
@@ -361,7 +361,10 @@
/* XXX : BSD as more */
} sight_procstate_e;
-apr_status_t sight_create_pool(apr_pool_t **, apr_pool_t *);
+apr_status_t sight_pool_create(apr_pool_t **, apr_pool_t *, int);
+apr_status_t sight_pool_clear(apr_pool_t *);
+apr_status_t sight_pool_lock(apr_thread_mutex_t **, apr_pool_t *);
+apr_status_t sight_pool_lock_parent(apr_thread_mutex_t **, apr_pool_t *);
jobjectArray sight_new_cc_array(JNIEnv *, sight_cclass_e, jsize);
jbyteArray sight_new_byte_array(JNIEnv *, jbyte *, jsize);
@@ -381,20 +384,23 @@
#define SIGHT_GLOBAL_TRY if (apr_atomic_inc32(sight_global_atomic))
#define SIGHT_GLOBAL_END() apr_atomic_dec32(sight_global_atomic)
#define SIGHT_GLOBAL_BRK() apr_atomic_dec32(sight_global_atomic)
-#define SIGHT_LOCAL_TRY(N) { apr_uint32_t _SGATOM = apr_atomic_inc32(sight_global_atomic); \
- if ((N)) apr_atomic_inc32(&(N)->refcount); \
- if ((N) && _SGATOM)
-#define SIGHT_LOCAL_END(N) apr_atomic_dec32(&(N)->refcount); } apr_atomic_dec32(sight_global_atomic)
-#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount); apr_atomic_dec32(sight_global_atomic)
+/* More then 256 references is insane */
+#define SIGHT_MAXLREF 256
+#define SIGHT_LOCAL_TRY(N) if ((N) && apr_atomic_inc32(&(N)->refcount) < SIGHT_MAXLREF) { \
+ if (apr_atomic_read32(&(N)->interrupted) == 0)
+
+#define SIGHT_LOCAL_END(N) } if ((N)) apr_atomic_dec32(&(N)->refcount)
+#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount)
+
#else
#define SIGHT_GLOBAL_TRY
-#define SIGHT_GLOBAL_END()
-#define SIGHT_GLOBAL_BRK()
+#define SIGHT_GLOBAL_END() (void)0
+#define SIGHT_GLOBAL_BRK() (void)0
#define SIGHT_LOCAL_TRY(N) if ((N))
-#define SIGHT_LOCAL_END(N)
-#define SIGHT_LOCAL_BRK(N)
+#define SIGHT_LOCAL_END(N) (void)0
+#define SIGHT_LOCAL_BRK(N) (void)0
#endif /* SIGHT_APR_REFCOUNT */
Modified: trunk/sight/native/share/dir.c
===================================================================
--- trunk/sight/native/share/dir.c 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/share/dir.c 2007-10-09 11:41:45 UTC (rev 1092)
@@ -159,7 +159,7 @@
UNREFERENCED_O;
SIGHT_GLOBAL_TRY {
- if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
+ if ((rv = apr_pool_create(&p, sight_temp_pool)) != APR_SUCCESS) {
throwAprException(_E, rv);
SIGHT_GLOBAL_BRK();
goto cleanup;
Modified: trunk/sight/native/share/file.c
===================================================================
--- trunk/sight/native/share/file.c 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/share/file.c 2007-10-09 11:41:45 UTC (rev 1092)
@@ -30,6 +30,7 @@
#include "sight_types.h"
extern apr_pool_t *sight_global_pool;
+extern apr_pool_t *sight_temp_pool;
static void file_cleanup(int mode, sight_object_t *no)
{
@@ -497,23 +498,25 @@
SIGHT_ALLOC_CSTRING(name);
UNREFERENCED_O;
- if (!sight_global_pool) {
- throwNullPointerException(_E, THROW_FMARK,
- sight_strerror(SIGHT_ENOPOOL));
- rv = APR_ENOPOOL;
- goto cleanup;
- }
- if ((rv = apr_pool_create(&p, sight_global_pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
- p = NULL;
- goto cleanup;
- }
- rv = apr_file_attrs_set(J2S(name), fa, fm, p);
- if (rv != APR_SUCCESS)
- throwAprException(_E, rv);
-cleanup:
- if (sight_global_pool && p)
- apr_pool_destroy(p);
+ SIGHT_GLOBAL_TRY {
+ if (!sight_temp_pool) {
+ throwNullPointerException(_E, THROW_FMARK,
+ sight_strerror(SIGHT_ENOPOOL));
+ rv = APR_ENOPOOL;
+ goto cleanup;
+ }
+ if ((rv = apr_pool_create(&p, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprException(_E, rv);
+ p = NULL;
+ goto cleanup;
+ }
+ rv = apr_file_attrs_set(J2S(name), fa, fm, p);
+ if (rv != APR_SUCCESS)
+ throwAprException(_E, rv);
+ cleanup:
+ if (sight_temp_pool && p)
+ apr_pool_destroy(p);
+ } SIGHT_GLOBAL_END();
SIGHT_FREE_CSTRING(name);
return rv;
}
Modified: trunk/sight/native/share/finfo.c
===================================================================
--- trunk/sight/native/share/finfo.c 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/share/finfo.c 2007-10-09 11:41:45 UTC (rev 1092)
@@ -206,8 +206,8 @@
SIGHT_ALLOC_CSTRING(name);
SIGHT_GLOBAL_TRY {
- if ((rv = sight_create_pool(&p, sight_temp_pool)) != APR_SUCCESS) {
- throwAprException(_E, rv);
+ if ((rv = apr_pool_create(&p, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rv);
}
else {
memset(&info, 0, sizeof(apr_finfo_t));
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/share/library.c 2007-10-09 11:41:45 UTC (rev 1092)
@@ -168,14 +168,12 @@
sight_unload_classes(_E);
return JNI_FALSE;
}
- if (apr_pool_create(&sight_global_pool, NULL) != APR_SUCCESS) {
+ if (sight_pool_create(&sight_global_pool, NULL, 1) != APR_SUCCESS) {
return JNI_FALSE;
}
- if (apr_pool_create(&sight_temp_pool, NULL) != APR_SUCCESS) {
+ if (sight_pool_create(&sight_temp_pool, NULL, 1) != APR_SUCCESS) {
return JNI_FALSE;
}
- apr_pool_tag(sight_global_pool, "sight_global_pool");
- apr_pool_tag(sight_temp_pool, "sight_temp_pool");
if (apr_thread_mutex_create(&sight_global_mutex,
APR_THREAD_MUTEX_DEFAULT,
@@ -184,6 +182,7 @@
}
apr_atomic_init(sight_global_pool);
if (sight_main(sight_global_pool) != APR_SUCCESS) {
+ apr_pool_destroy(sight_temp_pool);
apr_pool_destroy(sight_global_pool);
sight_global_pool = NULL;
sight_unload_classes(_E);
@@ -193,23 +192,89 @@
return JNI_TRUE;
}
-apr_status_t sight_create_pool(apr_pool_t **pool, apr_pool_t *parent)
+apr_status_t sight_pool_create(apr_pool_t **pool, apr_pool_t *parent,
+ int lockable)
{
+ apr_status_t rc;
apr_allocator_t *allocator = NULL;
- apr_status_t rc;
+ apr_thread_mutex_t *mutex = NULL;
- *pool = NULL;
- if ((rc = apr_allocator_create(&allocator)) != APR_SUCCESS) {
+ if ((rc = apr_allocator_create(&allocator)) != APR_SUCCESS)
return rc;
- }
- if ((rc = apr_pool_create_ex(pool, parent,
- NULL, allocator)) != APR_SUCCESS) {
+
+ if ((rc = apr_pool_create_ex(pool, parent, NULL,
+ allocator)) != APR_SUCCESS) {
+ apr_allocator_destroy(allocator);
return rc;
}
+ if (lockable) {
+ if ((rc = apr_thread_mutex_create(&mutex,
+ APR_THREAD_MUTEX_DEFAULT,
+ *pool)) != APR_SUCCESS) {
+ apr_allocator_destroy(allocator);
+ *pool = NULL;
+ return rc;
+ }
+
+ }
+ else if (parent) {
+ /* Use parents allocator mutex */
+ mutex = apr_allocator_mutex_get(apr_pool_allocator_get(parent));
+ }
+ apr_allocator_mutex_set(allocator, mutex);
apr_allocator_owner_set(allocator, *pool);
return APR_SUCCESS;
}
+apr_status_t sight_pool_clear(apr_pool_t *pool)
+{
+ apr_status_t rc;
+ apr_allocator_t *allocator = apr_pool_allocator_get(pool);
+ apr_thread_mutex_t *mutex = apr_allocator_mutex_get(allocator);
+
+ apr_pool_clear(pool);
+ if (mutex) {
+ mutex = NULL;
+ if ((rc = apr_thread_mutex_create(&mutex,
+ APR_THREAD_MUTEX_DEFAULT,
+ pool)) != APR_SUCCESS) {
+ return rc;
+ }
+ }
+ apr_allocator_mutex_set(allocator, mutex);
+ return APR_SUCCESS;
+}
+
+apr_status_t sight_pool_lock(apr_thread_mutex_t **mutex, apr_pool_t *pool)
+{
+ if (pool) {
+ apr_allocator_t *allocator = apr_pool_allocator_get(pool);
+ apr_thread_mutex_t *lock;
+
+ if ((lock = apr_allocator_mutex_get(allocator))) {
+ if (mutex)
+ *mutex = lock;
+ return apr_thread_mutex_lock(lock);
+ }
+ }
+ if (mutex)
+ *mutex = NULL;
+ return APR_ENOPOOL;
+}
+
+apr_status_t sight_pool_lock_parent(apr_thread_mutex_t **mutex, apr_pool_t *pool)
+{
+ if (pool) {
+ apr_pool_t *parent = apr_pool_parent_get(pool);
+ apr_allocator_t *allocator = apr_pool_allocator_get(parent);
+
+ if ((*mutex = apr_allocator_mutex_get(allocator)) != NULL)
+ return apr_thread_mutex_lock(*mutex);
+ }
+ *mutex = NULL;
+ return APR_SUCCESS;
+}
+
static void dump_stats()
{
fprintf(stderr, "\nNativeObject statistics ......\n");
@@ -245,6 +310,9 @@
fprintf(stderr, "\nLibrary terminate ............\n");
fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
#endif
+ sight_pool_lock(NULL, sight_temp_pool);
+ sight_pool_lock(NULL, sight_global_pool);
+
#if SIGHT_APR_REFCOUNT
/* Wait until all JNI calls are done
*/
@@ -334,6 +402,7 @@
SIGHT_EXPORT_DECLARE(void, Library, clear0)(SIGHT_STDARGS)
{
+ apr_status_t rc;
UNREFERENCED_O;
if (sight_global_pool) {
@@ -346,6 +415,9 @@
fprintf(stderr, "\nLibrary clear ................\n");
fprintf(stderr, "Global Atomic counter : %d\n", sight_global_a);
#endif
+ sight_pool_lock(NULL, sight_temp_pool);
+ sight_pool_lock(NULL, sight_global_pool);
+
#if SIGHT_APR_REFCOUNT
while (in_object_count) {
@@ -371,8 +443,15 @@
#endif
- apr_pool_clear(sight_global_pool);
+ sight_pool_clear(sight_temp_pool);
+ sight_pool_clear(sight_global_pool);
apr_atomic_set32(sight_global_atomic, 1);
+ if ((rc = apr_thread_mutex_create(&sight_global_mutex,
+ APR_THREAD_MUTEX_DEFAULT,
+ sight_global_pool)) != APR_SUCCESS) {
+ throwAprException(_E, rc);
+ return;
+ }
}
#ifdef SIGHT_DO_STATS
dump_stats();
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-06 09:53:30 UTC (rev 1091)
+++ trunk/sight/native/share/no.c 2007-10-09 11:41:45 UTC (rev 1092)
@@ -158,13 +158,15 @@
SIGHT_EXPORT_DECLARE(void, NativeObject, init0)(SIGHT_STDARGS,
jobject thiz,
jlong instance,
- jlong parent)
+ jlong parent,
+ jboolean lock)
{
jclass c;
apr_pool_t *pool = NULL;
sight_object_t *no = J2P(instance, sight_object_t *);
- apr_pool_t *pp = J2P(parent, apr_pool_t *);
+ apr_pool_t *ppool = J2P(parent, apr_pool_t *);
apr_status_t rc;
+ apr_thread_mutex_t *mutex;
UNREFERENCED_O;
@@ -173,13 +175,19 @@
#endif
if (!no)
return;
- SIGHT_GLOBAL_TRY {
- if (!pp)
- pp = sight_global_pool;
-
- if ((rc = sight_create_pool(&pool, pp)) != APR_SUCCESS) {
+ if (!ppool) {
+ /* Use the global pool */
+ ppool = sight_global_pool;
+ }
+ if (!ppool) {
+ /* Global pool is missing */
+ throwAprMemoryException(_E, THROW_FMARK, APR_ENOPOOL);
+ return;
+ }
+ if ((rc = sight_pool_lock(&mutex, ppool)) == APR_SUCCESS) {
+ if ((rc = sight_pool_create(&pool, ppool, lock)) != APR_SUCCESS) {
throwAprMemoryException(_E, THROW_FMARK, rc);
- SIGHT_GLOBAL_END();
+ apr_thread_mutex_unlock(mutex);
return;
}
@@ -191,8 +199,11 @@
native_object_cleanup,
apr_pool_cleanup_null);
SET_IFIELD_J(0001, no->object, P2J(pool));
-
- } SIGHT_GLOBAL_END();
+ apr_thread_mutex_unlock(mutex);
+ } else {
+ /* Pool is locked or invalid */
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ }
}
SIGHT_EXPORT_DECLARE(void, NativeObject, cbset0)(SIGHT_STDARGS,
@@ -226,6 +237,7 @@
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
+ apr_thread_mutex_t *mutex;
#if SIGHT_APR_REFCOUNT
apr_uint32_t ioc = 0;
apr_uint32_t refcount;
@@ -238,7 +250,8 @@
#endif
if (!no)
return;
- SIGHT_GLOBAL_TRY {
+ /* Check if parent is locked */
+ if (sight_pool_lock_parent(&mutex, no->pool) == APR_SUCCESS) {
apr_atomic_inc32(&no->interrupted);
if (no->object) {
object = (*_E)->NewLocalRef(_E, no->object);
@@ -284,14 +297,17 @@
(*_E)->DeleteLocalRef(_E, object);
if (no->cb.object)
(*_E)->DeleteGlobalRef(_E, no->cb.object);
+ if (mutex)
+ apr_thread_mutex_unlock(mutex);
free(no);
- } SIGHT_GLOBAL_END();
+ }
}
SIGHT_EXPORT_DECLARE(void, NativeObject, clear0)(SIGHT_STDARGS,
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
+ apr_thread_mutex_t *mutex;
#if SIGHT_APR_REFCOUNT
apr_uint32_t ioc = 0;
apr_uint32_t refcount;
@@ -303,7 +319,7 @@
#endif
if (!no)
return;
- SIGHT_GLOBAL_TRY {
+ if (sight_pool_lock_parent(&mutex, no->pool) == APR_SUCCESS) {
apr_atomic_inc32(&no->interrupted);
#if SIGHT_APR_REFCOUNT
refcount = apr_atomic_read32(&no->refcount);
@@ -333,7 +349,7 @@
if (no->clean)
(*no->clean)(POOL_CLEAR, no);
if (no->pool) {
- apr_pool_clear(no->pool);
+ sight_pool_clear(no->pool);
apr_pool_cleanup_register(no->pool, (const void *)no,
native_object_cleanup,
apr_pool_cleanup_null);
@@ -341,7 +357,9 @@
no->native = NULL;
}
apr_atomic_set32(&no->interrupted, 0);
- } SIGHT_GLOBAL_END();
+ if (mutex)
+ apr_thread_mutex_unlock(mutex);
+ }
}
SIGHT_EXPORT_DECLARE(void, NativeObject, intr0)(SIGHT_STDARGS,
17 years, 2 months
JBoss Native SVN: r1091 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-06 05:53:30 -0400 (Sat, 06 Oct 2007)
New Revision: 1091
Modified:
trunk/sight/native/share/no.c
Log:
Check JNI calls for apr_pool_clear
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-06 08:41:59 UTC (rev 1090)
+++ trunk/sight/native/share/no.c 2007-10-06 09:53:30 UTC (rev 1091)
@@ -29,6 +29,10 @@
#include "sight_local.h"
extern apr_pool_t *sight_global_pool;
+
+#define OPTIMISTIC_LOCK_CNT 10000
+#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
+
/*
* NativeObject
* This is the core of object management in SIGHT.
@@ -76,8 +80,13 @@
sight_cnt_native_pcleanup++;
#endif
if (data) {
+#if SIGHT_APR_REFCOUNT
+ apr_uint32_t ioc = 0;
+ apr_uint32_t refcount;
+#endif
JNIEnv *_E = NULL;
jint em = sight_get_jnienv(&_E);
+
if (_E && no->object) {
jobject object = (*_E)->NewLocalRef(_E, no->object);
(*_E)->DeleteWeakGlobalRef(_E, no->object);
@@ -98,6 +107,24 @@
no->object = NULL;
}
}
+ apr_atomic_inc32(&no->interrupted);
+#if SIGHT_APR_REFCOUNT
+ refcount = apr_atomic_read32(&no->refcount);
+ while (refcount) {
+ apr_thread_yield();
+ refcount = apr_atomic_read32(&no->refcount);
+ if (ioc++ > OPTIMISTIC_LOCK_CNT) {
+ /* Sleep one millisecond */
+ apr_sleep(1000L);
+ }
+ if (ioc > OPTIMISTIC_LOCK_MAX) {
+ /* TODO: We have a zombie or a lengthy JNI op.
+ * Find a way to bail out without crushing JVM
+ */
+ break;
+ }
+ }
+#endif
if (no->clean) {
(*no->clean)(POOL_CALLBACK, no);
}
@@ -194,15 +221,12 @@
} SIGHT_LOCAL_END(no);
}
-#define OPTIMISTIC_LOCK_CNT 10000
-#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
-
SIGHT_EXPORT_DECLARE(void, NativeObject, free0)(SIGHT_STDARGS,
jlong instance)
{
sight_object_t *no = J2P(instance, sight_object_t *);
jobject object = NULL;
-#if SIGHT_APR_REFCOUNT
+#if SIGHT_APR_REFCOUNT
apr_uint32_t ioc = 0;
apr_uint32_t refcount;
#endif
@@ -316,7 +340,7 @@
no->opaque = NULL;
no->native = NULL;
}
- apr_atomic_set32(&no->interrupted, 0);
+ apr_atomic_set32(&no->interrupted, 0);
} SIGHT_GLOBAL_END();
}
17 years, 2 months