예제 #1
1
  public static void main(String[] args) throws Exception {
    System.setSecurityManager(new SecurityManager());

    // Create an uninitialized class loader
    try {
      new ClassLoader(null) {
        @Override
        protected void finalize() {
          loader = this;
        }
      };
    } catch (SecurityException exc) {
      // Expected
    }
    System.gc();
    System.runFinalization();

    // if 'loader' isn't null, need to ensure that it can't be used as
    // parent
    if (loader != null) {
      try {
        // Create a class loader with 'loader' being the parent
        URLClassLoader child = URLClassLoader.newInstance(new URL[0], loader);
        throw new RuntimeException("Test Failed!");
      } catch (SecurityException se) {
        System.out.println("Test Passed: Exception thrown");
      }
    } else {
      System.out.println("Test Passed: Loader is null");
    }
  }
예제 #2
0
파일: Server.java 프로젝트: ThierryL/PacMan
 public void disconnect(String name, I_InfoPlayer player) {
   InfoGame tmpGame = game;
   I_InfoPlayer tmpPlayer = player;
   try {
     Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/I_InfoGame");
     Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/" + name);
   } catch (Exception e) {
     System.out.println("Failed unbind");
     System.exit(128);
   }
   game = null;
   player = null;
   System.gc();
   System.out.println("Disconnected");
   ServerTimer timer = new ServerTimer(5);
   Thread thread = new Thread(timer);
   thread.start();
   while (!timer.finished()) ;
   timer.shutDown();
   timer = null;
   System.gc();
   game = tmpGame;
   player = tmpPlayer;
   try {
     Naming.rebind("rmi://" + serverAddress + ":1099/I_InfoGame", game);
     Naming.rebind("rmi://" + serverAddress + ":1099/" + name, player);
   } catch (Exception e) {
     System.out.println("Failed rebind");
     System.exit(128);
   }
   System.out.println("Reconnected");
 }
예제 #3
0
파일: Server.java 프로젝트: ThierryL/PacMan
 private static void serverRunning() {
   System.out.println("Server Running");
   ServerTimer timer = new ServerTimer(60);
   Thread thread = new Thread(timer);
   thread.start();
   // System.out.println("Waiting for timer");
   while (!timer.finished()) ;
   timer.shutDown();
   // System.out.println("Migration !");
   timer = null;
   System.gc();
   try {
     game.setMoving(true);
     serverCall();
   } catch (RemoteException e) {
     System.out.println("Failed to modify game");
     System.exit(1);
   } catch (Exception ex) {
     System.out.println("Failed to call");
   }
 }
예제 #4
0
파일: Server.java 프로젝트: ThierryL/PacMan
  private static void serverCall() throws Exception {
    String sentence = "move";
    String line;

    while (!gameStopped) {
      System.out.print("");
    }
    playing = false;
    try {
      setDiscussion();
    } catch (Exception ex) {
      System.out.println("Failed to discuss with clients");
    }

    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    try {
      InetAddress inetAddress = InetAddress.getByName(serverInfo.getNext().getIpAddr());
      Socket clientSocket = new Socket(inetAddress, serverInfo.getNext().getPort());
      DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
      BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
      sendInfo(out);
      line = in.readLine();
      while (!game.getUnbinding()) ;
      Naming.unbind("rmi://" + serverInfo.getIpAddr() + ":1099/I_InfoGame");
      out.writeBytes("Unbinding finished\n");
      line = in.readLine();
      clientSocket.close();
    } catch (RemoteException e) {
      System.out.println("Failed get info from game");
      System.exit(1);
    } catch (Exception ex) {
      System.out.println("Failed to socket with waiting server");
    }
    discussion.shutDown();
    discussion = null;
    game = null;
    System.gc();
    serverWaiting();
  }
 @Scheduled(fixedDelay = SCHEDULED_CHECK)
 public void checkActiveClients() {
   Set<String> users = user_vidNameMap.keySet();
   Iterator<String> it = users.iterator();
   long time = System.currentTimeMillis();
   int count = 0;
   while (it.hasNext()) {
     count++;
     String user = it.next();
     if (user == null) continue;
     if (userAliveMap.containsKey(user)) {
       if (userAliveMap.get(user).longValue() < time) {
         removeUser(user);
         userAliveMap.remove(user);
       }
     } else {
       throw new RuntimeException("user in user-vid map but not in user-alive map");
     }
   }
   // System.out.println("Debug: Scheduled Check count:"+count+" user
   // count:"+user_vidNameMap.size());
   System.gc();
 }
예제 #6
0
 public void mousePressed(MouseEvent e) {
   Undo.reset();
   if (!Prefs.noClickToGC) System.gc();
   IJ.showStatus(version() + IJ.freeMemory());
   if (IJ.debugMode) IJ.log("Windows: " + WindowManager.getWindowCount());
 }
예제 #7
0
  protected void runOneSet(
      GLAutoDrawable drawable, String textBaseName, int numObjs, int numTextures, int loops) {
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    if (numTextures > MAX_TEXTURE_ENGINES) {
      throw new GLException("numTextures must be within 1.." + MAX_TEXTURE_ENGINES);
    }

    String textName = null;
    textDatas = new TextureData[numObjs];
    textures = new Texture[numTextures];
    try {
      for (int i = 0; i < numObjs; i++) {
        textName = "data/" + textBaseName + "." + (i + 1) + ".tga";
        URL urlText = IOUtil.getResource(Perftst.class, textName);
        if (urlText == null) {
          throw new RuntimeException("couldn't fetch " + textName);
        }
        textDatas[i] =
            TextureIO.newTextureData(gl.getGLProfile(), urlText.openStream(), false, TextureIO.TGA);
        System.out.println(textBaseName + ": " + textDatas[i]);
      }

      for (int i = 0; i < numTextures; i++) {
        gl.glActiveTexture(i);
        textures[i] = new Texture(GL.GL_TEXTURE_2D);
      }
    } catch (IOException ioe) {
      System.err.println("couldn't fetch " + textName);
      throw new RuntimeException(ioe);
    }

    //
    // Vertices Data setup
    //

    st.useProgram(gl, true);

    GLArrayDataServer vertices =
        GLArrayDataServer.createGLSL("mgl_Vertex", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
    {
      FloatBuffer vb = (FloatBuffer) vertices.getBuffer();
      vb.put(0f);
      vb.put(0f);
      vb.put(1f);
      vb.put(0f);
      vb.put(0f);
      vb.put(1f);
      vb.put(1f);
      vb.put(1f);
    }
    vertices.seal(gl, true);

    GLArrayDataServer texCoords =
        GLArrayDataServer.createGLSL(
            "mgl_MultiTexCoord0", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW);
    {
      FloatBuffer cb = (FloatBuffer) texCoords.getBuffer();
      cb.put(0f);
      cb.put(0f);
      cb.put(1f);
      cb.put(0f);
      cb.put(0f);
      cb.put(1f);
      cb.put(1f);
      cb.put(1f);
    }
    texCoords.seal(gl, true);

    //
    // texture setup
    //
    long[] tU = new long[numObjs + 1];
    tU[0] = System.currentTimeMillis();
    for (int j = 0; j < numTextures; j++) {
      gl.glActiveTexture(j);
      textures[j].updateImage(gl, textDatas[0]);
      tU[j + 1] = System.currentTimeMillis();
    }

    GLUniformData activeTexture = new GLUniformData("mgl_ActiveTexture", 0);
    st.uniform(gl, activeTexture);

    //
    // run loops
    //

    long dtC, dt, dt2, dt3, dtF, dtS, dtT;
    long[][] tC = new long[loops][numObjs];
    long[][] t0 = new long[loops][numObjs];
    long[][][] t1 = new long[loops][numObjs][numTextures];
    long[][][] t2 = new long[loops][numObjs][numTextures];
    long[][][] t3 = new long[loops][numObjs][numTextures];
    long[][] tF = new long[loops][numObjs];
    long[][] tS = new long[loops][numObjs];

    for (int i = 0; i < loops; i++) {
      for (int j = 0; j < numObjs; j++) {
        tC[i][j] = System.currentTimeMillis();

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);

        t0[i][j] = System.currentTimeMillis();

        for (int k = 0; k < numTextures; k++) {
          gl.glActiveTexture(GL.GL_TEXTURE0 + k);
          textures[k].enable(gl);
          textures[k].bind(gl);
          activeTexture.setData(k);
          st.uniform(gl, activeTexture);

          t1[i][j][k] = System.currentTimeMillis();

          textures[k].updateSubImage(gl, textDatas[j], 0, 0, 0);

          t2[i][j][k] = System.currentTimeMillis();

          gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, vertices.getElementCount());

          t3[i][j][k] = System.currentTimeMillis();
        }
        gl.glFinish();

        tF[i][j] = System.currentTimeMillis();

        drawable.swapBuffers();

        tS[i][j] = System.currentTimeMillis();

        /*try {
            Thread.sleep(100);
        } catch (Exception e) {} */
      }
    }

    int textBytes = 0;
    for (int j = 0; j < numObjs; j++) {
      textBytes += textDatas[j].getEstimatedMemorySize();
    }
    textBytes *= numTextures;

    dt = 0;
    for (int i = 1; i < loops; i++) {
      for (int j = 0; j < numObjs; j++) {
        dt += tS[i][j] - tC[i][j];
      }
    }

    System.out.println("");
    System.out.println(
        "Texture "
            + textBaseName
            + ", loops "
            + loops
            + ", textures "
            + numTextures
            + ", objects "
            + numObjs
            + ", total bytes "
            + textBytes
            + ", total time: "
            + dt
            + "ms, fps(-1): "
            + (((loops - 1) * numObjs * 1000) / dt)
            + ",\n text kB/s: "
            + (((double) (loops * textBytes) / 1024.0) / ((double) dt / 1000.0)));

    for (int i = 0; i < loops; i++) {
      dtC = 0;
      dtF = 0;
      dtS = 0;
      dtT = 0;
      for (int j = 0; j < numObjs; j++) {
        dtC += t0[i][j] - tC[i][j];
        dtF += tF[i][j] - t3[i][j][numTextures - 1];
        dtS += tS[i][j] - tF[i][j];
        dtT += tS[i][j] - tC[i][j];
      }
      if (dtT <= 0) dtT = 1;
      System.out.println(
          "\tloop "
              + i
              + ": clear "
              + dtC
              + "ms, finish "
              + dtF
              + ", swap "
              + dtS
              + "ms, total: "
              + dtT
              + "ms, fps "
              + (numObjs * 1000) / dtT);
      /*
      for(int j=0; j<dummyUni.length; j++) {
          dt = t1[i][j] - t0[i];
          dt2= t2[i][j] - t1[i][j];
          dt3= t3[i][j] - t2[i][j];
          dtT= dt+dt2+dt3;
          System.out.println("\t\tobj "+j+": setup "+dt +"ms, update "+dt2 +"ms, draw "+dt3+"ms, total: "+ dtT);
      } */
    }
    System.out.println("*****************************************************************");

    st.useProgram(gl, false);

    for (int i = 0; i < numTextures; i++) {
      textures[i].disable(gl);
      textures[i].destroy(gl);
      textures[i] = null;
    }
    for (int i = 0; i < numObjs; i++) {
      textDatas[i] = null;
    }
    textures = null;
    textDatas = null;
    System.gc();
    try {
      Thread.sleep(100);
    } catch (Exception e) {
    }
    System.gc();
  }