kdelibs/khtml/java

Koos Vriezen koos.vriezen at xs4all.nl
Mon Feb 7 21:47:14 GMT 2005


On Mon, Feb 07, 2005 at 05:28:31PM +0100, Paul Temple wrote:
> Have you done _real_ profiling yet? Is there a difference between 
> 1.4 and 5? I know from my experience with jbuilder, eclipse and 
> the likes that startup time decreased significantly with each 
> new major version.

Ok, did some profiling w/ a testkjs application.
Application compile as: g++ -o testkjsas testkjsas.cpp
Run as: time PATH=/usr/local/jdk1.5.0/bin:$PATH ./testkjsas file:///home/koos/public_html jsapplet
for a jsapplet.class inside my public_html directory
It's a matter of commenting the second argument for the console window
Results are

w/ creating a console window:
1.4
real    0m1.419s
user    0m0.001s
sys     0m0.002s

1.5
real    0m1.471s
user    0m0.003s
sys     0m0.001s

w/o creating a console window:
1.4.2_06
real    0m1.053s
user    0m0.001s
sys     0m0.001s

1.5
real    0m1.171s
user    0m0.001s
sys     0m0.002s

commenting 'console.setVisible( true );' out in Main.java:120
1.4.2_06
real    0m1.279s
user    0m0.000s
sys     0m0.004s

1.5
real    0m1.332s
user    0m0.001s
sys     0m0.001s

Note, numbers are after a few time to eliminate caching and seem to
stabalize arround these numbers. I would say that it's a major slowdown
showing a console window. Even creating w/o showing is about 20% slower.

Koos
-------------- next part --------------
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main (int argc, char ** argv) {
    char policy[256], jar_path[256];
    int stdin_pipe[2], stdout_pipe[2];
    if (argc < 3) {
        fprintf (stderr, "usage %s <codebase> <classname>\n", argv[0]);
        return 1;
    }
    char * kdedir = getenv ("KDEDIR");
    if (!kdedir)
        kdedir = "/usr";
    snprintf (policy, sizeof (policy), "-Djava.security.policy=%s/share/apps/kjava/kjava.policy", kdedir);
    snprintf (jar_path, sizeof (jar_path), "%s/share/apps/kjava/kjava.jar", kdedir);
    char * const jvm_argv [] = {
        "java"/*, "-Dkjas.showConsole"*/, "-DUseSecurityManager=true", policy,
        "-classpath",  jar_path, "org.kde.kjas.server.Main", 0L
    };
    if (pipe (stdin_pipe) || pipe (stdout_pipe)) {
        perror ("pipe");
        return -1;
    }
    int pid = fork ();
    switch (pid) {
        case -1: // error
            break;
        case 0: { // child
            close (0);
            dup (stdin_pipe[0]);
            close (stdin_pipe[0]);
            close (stdin_pipe[1]);
            close (1);
            dup (stdout_pipe[1]);
            close (stdout_pipe[0]);
            close (stdout_pipe[1]);
            execvp (jvm_argv[0], jvm_argv);        
            return 1;
        }
        default: // parent
            close (stdin_pipe[0]);
            close (stdout_pipe[1]);
            break;
    }
    const char * cmd = "3       \0010\0"; // create context 0
    write (stdin_pipe[1], cmd, 11); // 8 + 1 (code) + 1 (contextid) + 1 (sep)
    char buf[256] = "        ";
    int buf_pos = 8;
    buf [buf_pos++] = '\003'; // create applet code
    buf [buf_pos++] = '0'; // contextid
    buf [buf_pos++] = 0; // sep
    buf [buf_pos++] = '0'; // appletid
    buf [buf_pos++] = 0; // sep
    buf [buf_pos++] = 0; // name + sep
    strcpy (buf + buf_pos, argv[2]);  // classname
    buf_pos += strlen (argv[2]);
    buf [buf_pos++] = 0; // sep
    strcpy (buf + buf_pos, argv[1]);  // baseurl
    buf_pos += strlen (argv[1]);
    buf [buf_pos++] = 0; // sep
    buf [buf_pos++] = 0; // user + sep
    buf [buf_pos++] = 0; // passwd + sep
    buf [buf_pos++] = 0; // authname + sep
    strcpy (buf + buf_pos, argv[1]);  // codebase
    buf_pos += strlen (argv[1]);
    buf [buf_pos++] = 0; // sep
    buf [buf_pos++] = 0; // jarfile + sep
    strcpy (buf + buf_pos, "300");  // width
    buf_pos += 3;
    buf [buf_pos++] = 0; // sep
    strcpy (buf + buf_pos, "200");  // height
    buf_pos += 3;
    buf [buf_pos++] = 0; // sep
    buf [buf_pos++] = 0; // title + sep
    buf [buf_pos++] = '0'; // params
    buf [buf_pos++] = 0; // sep
    char num_buf [16];
    sprintf (num_buf, "%d", buf_pos-8);
    memcpy (buf, num_buf, strlen (num_buf));
    write (stdin_pipe[1], buf, buf_pos);
    while (true) {
        char lenstr[9];
        int num_bytes = read (stdout_pipe[0], lenstr, 8);
        if (num_bytes <= 0)
            exit (1);
        while (num_bytes < 8)
            num_bytes += read (stdout_pipe[0], lenstr+num_bytes, 8 - num_bytes);
        lenstr[8] = 0;
        int msg_len = strtol (lenstr, 0L, 10);
        if (msg_len < 0 || msg_len > 255) { // sanity check
            fprintf (stderr, "corrupted response\n");
            exit (1);
        }
        char * msg = new char [msg_len];
        num_bytes = read (stdout_pipe[0], msg, msg_len);
        if (num_bytes <= 0)
            exit (1);
        while (num_bytes < msg_len)
            num_bytes+= read (stdout_pipe[0], msg+num_bytes, msg_len-num_bytes);
        if (msg[0] == 23 && msg_len > 6) {
            if (msg[6] == '1')
                fprintf (stderr, "applet created\n");
            else if (msg[6] == '2')
                fprintf (stderr, "applet instanciated\n");
            else if (msg[6] == '3') {
                fprintf (stderr, "applet initialized\n");
                exit (0);
            }
        }
        delete [] msg;
    }
    return 0;
}


More information about the kfm-devel mailing list