You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by dl...@apache.org on 2007/08/12 23:04:33 UTC
svn commit: r565148 -
/harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c
Author: dlydick
Date: Sun Aug 12 14:04:32 2007
New Revision: 565148
URL: http://svn.apache.org/viewvc?view=rev&rev=565148
Log:
If-def'ed out and made 'static' old classfile read code, namely
classfile_read_classfile() and classfile_read_jarfile().
Replaced these with classfile_read(), which searches Java
archive files also.
Modified:
harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c
Modified: harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c?view=diff&rev=565148&r1=565147&r2=565148
==============================================================================
--- harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c (original)
+++ harmony/enhanced/sandbox/bootjvm/bootJVM/jvm/src/classfile.c Sun Aug 12 14:04:32 2007
@@ -1670,20 +1670,12 @@
rnull, \
rnull)
+#warning Remove entire block once new functionality verified
+#if 0
/*!
* @name Read Java object code (class data) from disk files.
*
*
- * @param filename Null-terminated ASCII string, pathname
- * of JAR file or class file.
- *
- *
- * @returns Pointer to memory area containing class file data.
- * If error detected, @link #rnull rnull@endlink is
- * returned and perror("msg") may be called to report
- * the system call problem that caused the
- * particular failure more.
- *
*/
/*@{ */ /* Begin grouped definitions */
@@ -1694,8 +1686,18 @@
* If a valid class file is read, return pointer to memory area
* containing its Java class image.
*
+ *
+ * @param filename Null-terminated ASCII string, pathname
+ * of JAR file or class file.
+ *
+ * @returns Pointer to memory area containing class file data.
+ * If error detected, @link #rnull rnull@endlink is
+ * returned and perror("msg") may be called to report
+ * the system call problem that caused the
+ * particular failure more.
+ *
*/
-u1 *classfile_read_classfile(rchar *filename)
+static u1 *classfile_read_classfile(rchar *filename)
{
ARCH_FUNCTION_NAME(classfile_read_classfile);
@@ -1759,8 +1761,18 @@
* be available for loading from the temporary disk area via
* @b CLASSPATH.
*
+ *
+ * @param filename Null-terminated ASCII string, pathname
+ * of JAR file or class file.
+ *
+ * @returns Pointer to memory area containing class file data.
+ * If error detected, @link #rnull rnull@endlink is
+ * returned and perror("msg") may be called to report
+ * the system call problem that caused the
+ * particular failure more.
+ *
*/
-u1 *classfile_read_jarfile(rchar *filename)
+static u1 *classfile_read_jarfile(rchar *filename)
{
ARCH_FUNCTION_NAME(classfile_read_jarfile);
@@ -1843,20 +1855,19 @@
/* Read manifest file and locate starting class name */
- rchar *mnfstartclass = manifest_get_main(jarscript);
+ rchar *mnfstartclass = manifest_get_main_from_file(jarscript);
if (rnull == mnfstartclass)
{
sysErrMsg(arch_function_name,
- "Cannot locate start class in JAR file %s",
- jarparm);
- exit_jvm(EXIT_CLASSPATH_JAR);
+ "Startup class not found in JAR manifest file");
+ exit_jvm(EXIT_MANIFEST_JAR);
/*NOTREACHED*/
}
/* Reuse unneeded bfr w/ descriptive name */
rchar *start_class_tmpfile = pwd;
-
+
/* Verify existence of start class in JAR file */
sprintfLocal(start_class_tmpfile,
"%s%c",
@@ -1864,16 +1875,18 @@
JVMCFG_PATHNAME_DELIMITER_CHAR);
int dirlen = portable_strlen(start_class_tmpfile);
- portable_strcat(pwd, mnfstartclass);
+ portable_strcat(start_class_tmpfile, mnfstartclass);
- (rvoid) classpath_external2internal_classname_inplace(&pwd[dirlen]);
+ (rvoid) classpath_external2internal_classname_inplace(
+ &start_class_tmpfile[dirlen]);
int alllen = portable_strlen(start_class_tmpfile);
start_class_tmpfile[alllen] = JVMCFG_EXTENSION_DELIMITER_CHAR;
start_class_tmpfile[alllen + 1] = '\0';
- portable_strcat(pwd, CLASSFILE_EXTENSION_DEFAULT);
+ portable_strcat(start_class_tmpfile, CLASSFILE_EXTENSION_DEFAULT);
statbfr = portable_stat(start_class_tmpfile);
+ HEAP_FREE_DATA(statbfr);
/* Complain if class in manifest was not found in JAR file */
if (rnull == statbfr)
@@ -1906,10 +1919,143 @@
HEAP_FREE_DATA(start_class_tmpfile);
return(pvrc);
-
} /* END of classfile_read_jarfile() */
/*@} */ /* End of grouped definitions */
+#endif
+
+
+/*!
+ * @name Read Java object code (class data) from @b CLASSPATH location.
+ *
+ * Read Java object code either from an open JAR file or from a class
+ * file.
+ *
+ *
+ * @param pcpsr Pointer to @b CLASSPATH search result structure,
+ * indicating either a JAR file member or class file.
+ * This heap pointer is freed once it has been used.
+ *
+ * @param freecpsr Free the pointer to @b CLASSPATH search result
+ * if @link #rtrue rtrue@endlink and the caller does
+ * not need the pointer at a later time. Otherwise,
+ * the caller must free this pointer with a call to
+ * @link #classpath_free_search_result()
+ classpath_free_search_result()@endlink .
+ *
+ *
+ * @returns Pointer to memory area containing class file data.
+ * If error detected, @link #rnull rnull@endlink is returned.
+ * The diagnostic from the subsidiary call to either
+ * classfile_read_jarfile() or classfile_read_classfile() may
+ * be examined to learn what the problem was.
+ *
+ */
+u1 *classfile_read(classpath_search *pcpsr, rboolean freecpsr)
+{
+ ARCH_FUNCTION_NAME(classfile_read);
+
+ u1 *rc;
+
+ if (rnull != pcpsr->jarfile_member_state)
+ {
+ jarutil_read_current_member(pcpsr->jarfile_member_state);
+
+ /* Result will be a valid buffer or null pointer */
+ if (JAR_OKAY == pcpsr->jarfile_member_state->jar_code)
+ {
+ rc = pcpsr->jarfile_member_state->bfr;
+ }
+ else
+ {
+ /* Probably redundant */
+ rc = (u1 *) rnull;
+ }
+
+ portable_close(pcpsr->jarfile_member_state->fd);
+
+ if (rtrue == freecpsr)
+ {
+ HEAP_FREE_DATA(pcpsr->jarfile_member_state);
+ }
+ }
+ else
+ {
+ if (rnull != pcpsr->classfile_name)
+ {
+ off_t filesize = 0;
+
+ /* Portability library does (struct stat) part */
+ rvoid *statbfr;
+
+ rvoid *pclassfile_image;
+
+ int fd;
+
+ /*
+ * Check if file is available and read its
+ * stat info, esp file size
+ */
+ statbfr = portable_stat(pcpsr->classfile_name);
+
+ READ_SYSCALL_FAILURE(rnull == statbfr, "statbfr");
+
+ rlong get_st_size = portable_stat_get_st_size(statbfr);
+ HEAP_FREE_DATA(statbfr);
+
+ /*
+ * Allocate enough space for entire class file to be
+ * Read into memory at once.
+ */
+ pclassfile_image = (rvoid *) HEAP_GET_DATA(get_st_size,
+ rfalse);
+
+ /* Now go open the file and read it */
+ fd = portable_open(pcpsr->classfile_name, O_RDONLY);
+ READ_SYSCALL_FAILURE(0 > fd, "file open");
+
+ /* Read the whole file in at once and close it. */
+ filesize = portable_read(fd, pclassfile_image, get_st_size);
+ READ_SYSCALL_FAILURE(0 > filesize, "file read");
+
+ portable_close(fd);
+
+ /* Make sure stat() and read() have the same size */
+ GENERIC_FAILURE_PTR((filesize != get_st_size),
+ DMLNORM,
+ arch_function_name,
+ "Incomplete file read",
+ rvoid,
+ pclassfile_image,
+ rnull);
+
+ /* Proper completion when entire file is read in */
+ rc = pclassfile_image;
+
+ if (rtrue == freecpsr)
+ {
+ HEAP_FREE_DATA(pcpsr->classfile_name);
+ }
+ }
+ else
+ {
+ /*
+ * This state should NEVER be reached or @b pcpsr is invalid
+ */
+ rc = (u1 *) rnull;
+ }
+ }
+
+ /* Done with CLASSPATH search result */
+ if (rtrue == freecpsr)
+ {
+ HEAP_FREE_DATA(pcpsr);
+ }
+
+ /* Report results */
+ return(rc);
+
+} /* END of classfile_read() */
/* EOF */