code: private void optimize(final Subject subject) {
          if (System.getSecurityManager() == null)
              subject.setReadOnly();
          else
              AccessController.doPrivileged(new PrivilegedAction<Void>() {
                  @Override
                  public Void run() {
                      subject.setReadOnly();
                      return null;
                  }
              });
      }
docs: To optimize the subject the subject must be marked as read only and be placed in the cache.